jQuery网页右侧广告跟随滚动代码分享
jQuery广告跟随滚动的两种方法都分享给大家,希望对大家的学习有所启发。
方法一:
<scripttype="text/javascript">//<![CDATA[
$.fn.smartFloat=function(){
varposition=function(element){
vartop=element.position().top,pos=element.css("position");
$(window).scroll(function(){
varscrolls=$(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
});
}
});
});
<divid="float"class="float">
<h3>博主推荐</h3>
广告代码
</div>
以上就是jQuery网页右侧广告跟随滚动,仿wordpress右侧广告跟随滚动,希望对大家的学习有所帮助。
热门推荐
10 寒露祝福语毕业寄语简短
11 端午的祝福语毕业简短
12 50多岁生日简短祝福语
13 养生祝福语女生短句简短
14 2026简短祝福语给老师
15 网名简短祝福语搞笑男
16 祝福语签名简短大全女生
17 护士辞职送行祝福语简短
18 高温祝福语短语大全简短