2

我的页面上有 div.triangle,透明度为 0
,一旦页面底部被击中,我希望它淡入不透明度 .95,
然后,我希望它滚动到 $(".container") 的顶部一次 $ (“.triangle”)再次点击
我到目前为止,我想我已经得到了大部分的权利,除了事件?

   <script type="text/javascript">
      $(document).ready(function(){
          $(".container").scroll(function(){
              var currentPosition = $(document).scrollTop(); 
              var totalHeight = $(document).offsetHeight;
              var visibleHeight = $(document).clientHeight;
                  if (visibleHeight + currentPosition >= totalHeight){
                      $(".triangle").fadeTo("slow",.95);
                  }
          });
          $(".triangle").click(function(){
              $(".container").animate({scrollTop:0}, 'slow');
              $(".triangle").fadeTo("slow",0);
          });
      });
   </script>
4

1 回答 1

1

试试这个:

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

      $(".triangle").click(function(){
          $('html, body').animate({scrollTop:0}, 'slow');
          $(".triangle").fadeOut("slow");
      });
  });
于 2012-06-02T12:10:32.833 回答