欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery網(wǎng)頁右側(cè)廣告跟隨滾動(dòng)代碼分享

 更新時(shí)間:2020年04月20日 17:04:24   投稿:lijiao  
這篇文章主要介紹了兩種jQuery實(shí)現(xiàn)網(wǎng)頁右側(cè)廣告跟隨滾動(dòng)的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

jQuery廣告跟隨滾動(dòng)的兩種方法都分享給大家,希望對(duì)大家的學(xué)習(xí)有所啟發(fā)。

方法一:

<script type="text/javascript">// <![CDATA[ 
$.fn.smartFloat = function() { 
 var position = function(element) { 
  var top = element.position().top, pos = element.css("position"); 
  $(window).scroll(function() { 
   var scrolls = $(this).scrollTop(); 
   if (scrolls > top) { 
    if (window.XMLHttpRequest) { 
     element.css({ 
      position: "fixed", 
      top: "10px" 
     }); 
    } else { 
     element.css({ 
      top: scrolls 
     }); 
    } 
   }else { 
    element.css({ 
     position: pos, 
     top: top 
    }); 
   } 
  }); 
 }; 
 return $(this).each(function() { 
  position($(this)); 
 }); 
}; 
 
//綁定 
$("#float").smartFloat(); 
// ]]></script> 

方法二:

/*頁面智能層浮動(dòng)*/ 
jQuery(document).ready(function($){ 
 var $sidebar = $(".float"), 
 $window = $(window), 
 offset = $sidebar.offset(), 
 topPadding = 20; 
 $window.scroll(function() { 
  if ($window.scrollTop() > offset.top) { 
   $sidebar.stop().animate({ 
    marginTop: $window.scrollTop() - offset.top + topPadding 
   }); 
  } else { 
   $sidebar.stop().animate({ 
    marginTop: 0 
   }); 
  } 
 }); 
}); 
<div id="float" class="float"> 
<h3>博主推薦</h3> 
廣告代碼 
</div>

以上就是jQuery網(wǎng)頁右側(cè)廣告跟隨滾動(dòng),仿wordpress右側(cè)廣告跟隨滾動(dòng),希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評(píng)論