自己找了很久 分享出来,希望可以帮到大家
底部悬浮广告代码
@mediascreenand(max-device-width:800px){/**WAP**/
.bottom_fixed{position:fixed;bottom:0px;width:100%;z-index:99999;}
.bottom_fixeddiv{width:30px;height:30px;text-align:center;line-height:30px;background:#CCC;right:0;top:-30px;position:absolute;cursor:pointer;}
.bottom_fixeddiv:hover{background:#F66;color:#FFF}
.bottom_fixedaimg{height:80px;width:100%;}
}
@mediascreenand(min-width:800px){/**PC**/
.bottom_fixed{display:none;position:fixed;bottom:0px;left:50%;margin-left:-475px;z-index:99999;}
.bottom_fixeddiv{width:24px;height:24px;text-align:center;line-height:24px;background:#CCC;right:0;top:-24px;position:absolute;cursor:pointer}
.bottom_fixeddiv:hover{background:#F66;color:#FFF}
.bottom_fixedaimg{height:75px;width:950px;}
}
//Math.floor(Math.random()*10+1);
window.onload=function(){
vara=newArray();
a[0]='/mw690/0060lm7Tly1fwnrr9i7e7g30hs02840e.gif';
a[1]='/mw690/0060lm7Tly1fwnrr7p1ezg30qo01eaad.gif'
varb=Math.floor(Math.random()*10+1);
document.getElementById('img').src=a[b%2];
}
顶部悬浮广告代码
@mediascreenand(max-device-width:800px){
#float_banner{position:absolute;top:0;width:100%;height:30px;line-height:30px;text-align:center;background:#000;color:#fff;font-size:14px;font-weight:bold;z-index:2;}
}
@mediascreenand(min-width:800px){
#float_banner{display:none;position:absolute;top:0;width:100%;height:30px;line-height:30px;text-align:center;background:#000;color:#fff;font-size:14px;font-weight:bold;z-index:2;}
}
varspeed=100;
varscrollTop=null;
varhold=0;
varfloat_banner;
varpos=null;
vartimer=null;
varmoveHeight=null;
float_banner=document.getElementById("float_banner");
window.οnscrοll=scroll_ad;
functionscroll_ad(){
scrollTop=document.documentElement.scrollTop+document.body.scrollTop;
pos=scrollTop-float_banner.offsetTop;
pos=pos/10
moveHeight=pos>0?Math.ceil(pos):Math.floor(pos);
if(moveHeight!=0){
float_banner.style.top=float_banner.offsetTop+moveHeight+"px";
setTimeout(scroll_ad,speed);
}
}