jQuery tooltip detect screen edge

拥有回忆 提交于 2019-12-08 05:32:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!