网页中常会用到固定层这样的效果,可以放广告,可以放标签,可以放关注。
js代码如下
if ($('#follow-us')){ var followUsPosition = $('#follow-us').offset().top; window.onscroll = function () { var nowPosition = document.documentElement.scrollTop; if (nowPosition - followUsPosition > 0 ) { setTimeout(function () { $('#follow-us').attr('class','guanzhu'); },150); }else { $('#follow-us').attr('class','guanzhu'); } }; } });
Html代码:
<div class="guanzhu" id="follow-us"> <h2 class="hometitle">关注我们 么么哒!</h2> <ul> <li class="sina"><a href="/" target="_blank"><span>新浪微博</span>xxx博客</a></li> <li class="tencent"><a href="/" target="_blank"><span>腾讯微博</span>xxx博客</a></li> <li class="QQ"><a href="/" target="_blank"><span>QQ号</span>888888</a></li> <li class="emAIl"><a href="/" target="_blank"><span>邮箱帐号</span>888@qq.com</a></li> <li class="wxgzh"><a href="/" target="_blank"><span>微信号</span>123456789</a></li> <li class="wx"><img src="images/wx.jpg"></li> </ul> </div>
框架CSS样式(细节样式请自行添加)
/*guanzhu*/ .guanzhu { width: 300px; top: 100px; z-index: 999; position: fixed; _position: absolute; _top:expression(documentElement.scrollTop + 0 + "px"); _margin-top: 100px; }