HTML代码(即需要漂浮的广告): <div class="christmas_ad" style="width:155px; height:220px; position:absolute; top:250px; right:25px;"> <a href="javascript:void(0)" ><img src="/themes/mall/wowsai/topics/images/christmas_2012/christmasAcvance.png" border="0" /></a> </div> js代码:前提是必须要引入jquery文件 <script type="text/javascript"> $(function(){ $(window).scroll(function(){ var scrollTop = document.body.scrollTop || document.documentElement.scrollTop || 0; $(".christmas_ad").stop(); var scrollTop2 = (scrollTop+160) - $(".christmas_ad").position().top; if(scrollTop> 440){ $(".christmas_ad:not(:animated)").animate({top:"+="+scrollTop2+"px"},1000); }else{ $(".christmas_ad").css("top",370+"px"); } }) }) </script>
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/8734.html