2010-06-16 2 views
1

메뉴 위에 떠있는 표시기 설정이 있습니다. 문제는 누군가가 '표시가 같은 장소에 머문'크기를 조정할 때 페이지가 '올바르게 배치되도록 새로 고침'해야한다는 것입니다. 페이지 크기가 조정되는 것을 감지하면 페이지 자체를 새로 고치는 방법은 무엇입니까? 또는 더 좋은 방법이 있습니까? 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> 

답변

1

에 부착해야 할 수있는 창 크기 조정 이벤트가 있습니다. 처음에는 지표를 배치하는 데 사용한 코드를 다시 실행하기 만하면됩니다.

Cross-browser window resize event - JavaScript/jQuery

+0

뛰어난 아이디어. 그것은 작동합니다. 이걸 사용하겠습니다. 감사합니다. u 너무 많이 – Maju

2

당신이처럼 .resize() 핸들러를 사용할 수 있습니다 :

$(window).resize(setNotifications); 
+0

좋은 해결책. 작동 중입니다. 감사합니다. – Maju

0

나는 이것이 잘 작동 생각

이 질문은 resize 이벤트를 사용하는 방법에 대한 좋은 해답을 가지고있다. IE Chrome 및 Firefox에서 확인했습니다.

$ (창) .bind ('크기 조정'기능() {

window.location.href = window.location.href; 

});

관련 문제