2012-03-01 4 views
1

Hello 바 위치 지정에 문제가 있습니다. CSS에서는 사이트를 푸시 한 친척입니다. 내가 페이지를 아래로 스크롤하고 내용이 바 뒤에보다는 사이트 상단에 백업을받을 경우, 나는이 문제를 해결할 수있는 방법 ..자바 스크립트 위치 지정

<script language="javascript"> 
$(window).scroll(function(){ 
var $this = $(this); 
$("#hello_bar").css("position", "fixed"); 
$('#hello_bar').css('position', "absolute" - $this.scrollTop()); 
}); 
</script> 

:이 문제를 해결하려면,이 자바 스크립트 함수를 사용할 수 있습니까?

답변

0

집합 다음 요소에 padding-top합니다 (p 태그) height#hello_bar DIV의 padding-top/padding-bottompadding-top 당량을 가지고. 이 숫자는 귀하의 경우 60px입니다. 또한이 기능은 이미 한 번 수행 된 후에 CPU 리소스가 낭비되므로 실제로이 기능을 한 번만 수행해야합니다.

var executedOnceBool = false;  
$(window).scroll(function(){ 
if (true === executedOnceBool) { 
    return; 
} 
var helloBarEl = $("#hello_bar"), 
    nextEl = helloBarEl.next(); // p 
    nextElPaddingTopNum = helloBarEl.css('padding-top') 
     + parseInt(helloBarEl.css('padding-bottom')) // 10 
     + parseInt(helloBarEl.css('padding-top')) // 10 
     + helloBarEl.css('height'); // 40, total = 60 

    nextEl.css('padding-top', nextElPaddingTopNum + 'px'); 
    executedOnceBool = true; 
}); 
0

위치를 "절대"에서 "상대"로 변경하십시오.

+0

고마워하지만 고칠 수는 없습니다. 미리보기 : http://ifixed.at/ – karabey