jQuery网页右侧广告跟随滚动代码分享
两种方法都分享给大家,希望对大家的学习有所启发。
方法一:
<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>
方法二:
/*页面智能层浮动*/ 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网页右侧广告跟随滚动,仿wordpress右侧广告跟随滚动,希望对大家的学习有所帮助。
jQuery插件Timelinr 实现时间轴特效
前言这是一款可用于展示历史和计划的时间轴插件,尤其比较适合一些网站展示发展历程、大事件等场景。该插件基于jQuery,可以滑动切换、水平和垂
推荐10 个很棒的 jQuery 特效代码
1.图片预加载(function($){varcache=[];//Argumentsareimagepathsrelativetothecurrentpage.$.preLoadImages=function(){varargs_len=arguments.length;for(vari=args_len;i--;){varcacheImage=document.create
分享五个有用的jquery小技巧
下文里技巧实现的效果虽然并不新鲜,但通过jQuery的封装,HTML实现了很大的清洁。清爽简洁又高效的代码任何时候都是开发者所醉心追求的终极目标,