2012-07-05 5 views
4

내 웹 사이트에서 스크롤 버튼을 사용하고 있습니다. 이*** px로 스크롤했을 때만 요소를 볼 수있게 설정하십시오.

$(window).scroll(function() { 
    if ($(this).scrollTop()) { 
     $('#cttm:hidden').stop(true, true).fadeIn(); 
    } else { 
     $('#cttm').stop(true, true).fadeOut(); 
    } 
}); 


    $(document).ready(function(){ 
     var bottom = ($(window).outerHeight() - $(window).height()) - 150; // 150 pixel to the bottom of the page; 
     $(window).scroll(function(){ 
      if ($(window).scrollTop() >= bottom) { 
        $("#cttm").fadeTo("slow",.95); 
      } else { 
        $("#cttm").fadeOut("slow"); 
      } 
     }); 

     $("#cttm").click(function(){ 
      $('html, body').animate({scrollTop:0}, 'slow'); 
      $("#cttm").fadeOut("slow"); 
     }); 
    }); 

이 JQuery와 잘 작동하지만 난 우리가 같은 상단 또는 뭔가에서 200 픽셀로 스크롤 할 때 요소 만 표시 할 내가이 jQuery를 사용하고 있습니다. JQuery로 할 수있는 방법이 있습니까?

+0

코드가 작동합니다, 문제는 무엇인가? – undefined

+0

이 페이지를 http://template-designfbapp.blogspot.in/2012/06/test-post-with-text.html에서 확인할 수 있습니다. 오른쪽 상단 모서리에있는 스크롤바는 특정 지점. –

답변

4

창 높이가 필요하지 않습니다.

var isVisible = false; 
$(window).scroll(function(){ 
    var shouldBeVisible = $(window).scrollTop()>200; 
    if (shouldBeVisible && !isVisible) { 
      isVisible = true; 
      $('#mybutton').show(); 
    } else if (isVisible && !shouldBeVisible) { 
      isVisible = false; 
      $('#mybutton').hide(); 
    } 
}); 

데모 : http://jsfiddle.net/dystroy/gXSLE/

관련 문제