2012-08-30 2 views
1

누구든지이 자바 스크립트를 도와 줄 수 있습니까?jQuery .scrollTop confusion

1000 픽셀 이상 아래로 스크롤 할 때 div을 표시하려면, 현재 아래 스크립트에서 작동하지만 스크롤 할 때 바로 표시됩니다.

>1000으로 설정을 시도했는데 전혀 표시되지 않습니까?

아이디어가 있으십니까?

$(window).scroll(function(){ 

    /* Check the location of each desired element */ 
    $('.hideme').each(function(i){ 

     /* If the object is completely visible in the window, fade it in */ 
     if ($(this).scrollTop() < 1000){ 
      $(this).animate({'opacity':'1'},900); 
     } 
    }); 
}); 
+0

유 제발 그것과 함께 당신의 CSS를 포함 할 수 있습니다. –

답변

1

도움이 되었으면 좋겠습니까? 나는 약간 희망 당신은 무엇을 알 수 기능을 변경했습니다

<html> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> 
    <script> 
    $(window).scroll(function(){ 
     /* Check the location of each desired element */ 
     $('.hideme').each(function(i){ 
      console.log($(window).scrollTop()); 
      if ($(window).scrollTop() < 500){ 
       $(this).stop().animate({ 
        opacity: 1.0 
       },900); 
      } else { 
       $(this).stop().animate({ 
        opacity: 0.0 
       },900); 
      } 
     }); 
    }); 
    </script> 
</head> 
<body style="height: 1500px;"> 

<div style="width: 400px; height: 50px; position: absolute; top: 500px; background-color: silver; opacity: 0.0;" class="hideme">asdsa</div> 

</body> 
</html> 

는)

0

오, 친애은 .. 고정 :)

경우 ($ (창) .scrollTop()> 1200) {

가 아니라 .hideme div의 창에서 설정하는 데 필요한 ($이)

+0

젠장, 너는 나를 때렸다 !! –

+0

하하 :) 어떻게하면 다시 스크롤 할 때 희미해질까요? – Brent

+0

답변 추가! –