2016年4月26日 星期二

[Jquery]scrollTop 滑鼠滾到指定位置,顯現DIV(浮水印 Top)

  1. $(function(){
  2. $(window).scroll(function () {
  3. if ($(this).scrollTop() > 800) {
  4. $('.left_BOX').fadeIn("fast");
  5. } else {
  6. $('.left_BOX').stop().fadeOut("fast");
  7. }
  8. });
  9. });


<div class="left_BOX" style="display: none; position: fixed;">
    <div class="goTop" style="display: none;position: fixed;margin-top: 60px;">
       <a href="#"></a>
    </div>
</div>

幾個重點 :

滑鼠要滾到指定位置,才會出現元素 => 預設是看不見的 display:none

元素要固定在頁面的某處 ==>  position: fixed

至於固定的位置可以用 top left right bottom 自行隨意調整


goTop比較簡單的寫法 可以設置連結(#) 就可以回到最頂端了




沒有留言:

張貼留言