jquery如何在调整大小时刷新页面?
问题描述:
我有一些指标显示设置漂浮在菜单上方。问题在于有人调整'指标停留在同一地点'时,页面需要'刷新以正确定位'。当它检测到页面被调整大小时如何自己刷新页面? 或者有没有更好的方法来做到这一点? jQuery的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
<li class="settings"><a class="settings" href="#">Settings</a>
<ul>
<li><a href="#">Game Settings</a></li>
<li><a href="#">Transactions </a></li>
</ul>
</li>
答
有可以挂接到窗口resize事件。只需重新运行您用于初始定位指标的代码,它应该都可以工作。
这个问题有关于使用resize事件很好的答案:
答
我觉得这个效果很好。在IE浏览器和Firefox上检查。
$(窗口).bind( '调整大小',函数(){
window.location.href = window.location.href;
});
绝妙的主意。有用。 Iam使用这一个。谢谢你这么多 – Maju 2010-06-16 10:45:06