欢迎各位兄弟 发布技术文章
这里的技术是共享的
先在html中引入 jquery文件 /** * Created by Administrator on 2016/6/22. */ var agt = navigator.userAgent.toLowerCase(); var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); var is_ie6 = is_ie && /msie (\d)\./.test(agt) && parseInt(RegExp.$1) < 7; var navobject = document.getElementById("nav_yykc"); var offsetTopInit = navobject.offsetTop; $(document).ready(function(e) { function sc5() { //not ie6 if (!is_ie6) { if ( $(document).scrollTop() <= offsetTopInit) { navobject.style.position = 'absolute'; navobject.style.top = offsetTopInit + 'px'; //document.getElementById("nav").style.top=document.documentElement.scrollTop+128+"px"; } else { navobject.style.position = 'fixed'; navobject.style.top = "0px"; } } //ie6 else { if ($(document).scrollTop() <= offsetTopInit) { //navobject.style.position='absolute'; navobject.style.top = offsetTopInit + 'px'; } else { //navobject.style.position='absolute'; navobject.style.top = document.documentElement.scrollTop + 'px'; } } } window.onscroll = function () { sc5(); } });
//this for ie6
var tips;
var theTop = offsetTopInit;
var old = theTop;
function initFloatTips()
{
tips = navobject;
moveTips();
}
function moveTips()
{
var tt=20;
if(document.documentElement.scrollTop<=offsetTopInit){
navobject.style.position='absolute';
navobject.style.top=offsetTopInit+'px';
}
else{
navobject.style.position='absolute';
navobject.style.top=document.documentElement.scrollTop+'px';
}
setTimeout(moveTips,tt);
}
if(is_ie6){
initFloatTips();
}
下面一个稍微更简单的方法
$( document ).ready(function() { $(window).scroll(function () { if(getScrollTOP()>50){ $('.bianqian').css('top',0); }else{ $('.bianqian').css('top','inherit'); } }); });
position: fixed;
left: 0;
z-index: 2;