Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery如何在调整页面大小时刷新页面?_Jquery_Jquery Ui - Fatal编程技术网

jquery如何在调整页面大小时刷新页面?

jquery如何在调整页面大小时刷新页面?,jquery,jquery-ui,Jquery,Jquery Ui,我有一些指示器显示设置浮动在菜单上方。问题是当有人调整“指示器保持在同一位置”的大小时,页面需要“刷新以正确定位”。当检测到页面正在调整大小时,如何让页面自行刷新? 还是有更好的方法? jQuery function findPosY(b) { var a = 0; if (b.offsetParent) { while (1) { a += b.offsetTop; if (!b.offsetParent)

我有一些指示器显示设置浮动在菜单上方。问题是当有人调整“指示器保持在同一位置”的大小时,页面需要“刷新以正确定位”。当检测到页面正在调整大小时,如何让页面自行刷新? 还是有更好的方法? jQuery

    function findPosY(b) {
    var a = 0;
    if (b.offsetParent) {
        while (1) {
            a += b.offsetTop;
            if (!b.offsetParent) {
                break
            }
            b = b.offsetParent
        }
    } else {
        if (b.y) {
            a += b.y
        }
    }
    return a
}
function findPosX(b) {
    var a = 0;
    if (b.offsetParent) {
        while (1) {
            a += b.offsetLeft;
            if (!b.offsetParent) {
                break
            }
            b = b.offsetParent
        }
    } else {
        if (b.x) {
            a += b.x
        }
    }
    return a
}
function setNotifications() {
    $("#shortcut_notifications span").each(function () {
        if ($(this).attr("rel") != "") {
            target = $(this).attr("rel");
            if ($("#" + target).length > 0) {
                var a = findPosY(document.getElementById(target));
                var b = findPosX(document.getElementById(target));
                $(this).css("top", a - 31 + "px");//-24
                $(this).css("left", b + 83 + "px")//+60
            }
        }
    });
    $("#shortcut_notifications").css("display", "block")
}
CSS

#shortcut_notifications {
display:none;
}

.notification {
color:#fff;
font-weight:700;
text-shadow:1px 0 0 #333;
background:transparent url(../images/bg_notification.png) no-repeat center;
position: absolute;/*absolute*/
width:37px;/*37*/
height:37px;
display:block;
text-align:center;
padding-top:17px;
color:#ffffff;
}

#nav li {
    display:block;
    float:right;
    padding:19px 21px;
    text-align: left;
    position:relative;
    height:24px;
    font-size:16px;
}
HTML


  • 有一个窗口大小调整事件,可以挂接到该事件中。只需重新运行最初用于定位指示器的代码,就可以正常工作

    关于使用调整大小事件,此问题有很好的答案:

    您可以使用处理程序,如下所示:

    $(window).resize(setNotifications);
    

    我认为这很有效。检查IE浏览器和Firefox

    $(窗口).bind('resize',function(){

    }))

    $(window).resize(setNotifications);
    
     window.location.href = window.location.href;