/    Sign up×
Community /Pin to ProfileBookmark

Jquery Tooltips: How to position them within window?

Hi all,

I have this photo gallery that I’m setting up where I’ve used some jquery to pop a magnified view of an image when the mouse is hovered over the thumbnail. As it is right now, it always positions the magnified image with the top-left corner at the x and y position of the mouse cursor. What I need it to do is if the image is going to be displayed beyond the viewport, that it would change its positioning to the corner that will show the whole image.

Here’s my page so far:

[url]http://thekevbot.com/fresh/classic/gallery.html[/url]

Here’s my jquery script:

[CODE]<script type=”text/javascript”>

$(document).ready(function() {

//Select all anchor tag with rel set to tooltip
$(‘a[rel=tooltip]’).mouseover(function(e) {

//Grab the title attribute’s value and assign it to a variable
var tip = $(this).attr(‘title’);

//Remove the title attribute’s to avoid the native tooltip from the browser
$(this).attr(‘title’,”);

//Append the tooltip template and its value
$(this).append(‘<div id=”tooltip”><div class=”tipHeader”></div><div class=”tipBody”>’ + tip + ‘</div><div class=”tipFooter”></div></div>’);

//Show the tooltip with faceIn effect
$(‘#tooltip’).fadeIn(‘500’);
$(‘#tooltip’).fadeTo(’10’,1);

})[B].mousemove(function(e) {

//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
$(‘#tooltip’).css(‘top’, e.pageY + 10 );
$(‘#tooltip’).css(‘left’, e.pageX + 20 );[/B]

}).mouseout(function() {

//Put back the title attribute’s value
$(this).attr(‘title’,$(‘.tipBody’).html());

//Remove the appended tooltip template
$(this).children(‘div#tooltip’).remove();

});

});

</script>
[/CODE]

I’m sure that I’ll have to use some if/else statements in the bolded section, but I’m definitely NO expert with jQuery and I have no clue as to what needs to be done.

And the CSS for the Tooltip:

[CODE]#tooltip {
position:absolute;
z-index:1000;
}
#tooltip .tipBody {
background-color:#000;
padding-top: 5px;
padding-right: 5px;
padding-left: 5px;
}[/CODE]

Any tips or suggestions that you might have are greatly appreciated! ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@khaagauthorJun 17.2011 — Hopeful bump!
Copy linkTweet thisAlerts:
@khaagauthorJun 20.2011 — Last bump...
×

Success!

Help @khaag spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...