问题
I have some basic hover/tooltip code working that needs to be modified so that a second class name is added when the tooltip hits the edge of the browser window. Can anyone lend a hand?
this.tooltip = function () {
$(".challenge_card").hover(function (e) {
$(this).parent().append("<div id='tooltip'></div>");
$("#tooltip")
.fadeIn("fast");
},
function () {
$("#tooltip").remove();
});
};
回答1:
var wW = $(window).width();
var $tooltip = $('#tooltip');
if($tooltip.offset().left + $tooltip.outerWidth() > wW){
// You've hit the right side of the browser window
}
Something like this should work - doesn't take into account the top position of course, but gives you the basic logic to check the position of the tooltip...
来源:https://stackoverflow.com/questions/13461096/jquery-tooltip-detect-screen-edge