JS模拟fixed效果。如何解决晃动问题。也就是跟fixed效果一摸一样。
既然fixed浏览器已经实现,真的就没办法模拟出来吗?!!<div style="width:100%;height:2000px;border:1px red solid;"></div>
<div id="test" style="position:absolute;left:50px;top:0px;background:url(http://avatar.profile.csdn.net/F/4/2/2_gkw521.jpg);width:100px;height:100px;"></div>
<script>
var dom=document.getElementById('test');
var =true,timeID,num=0;;
var setPos=function(){
f=false;
clearInterval(timeID);
timeID=setInterval(function(){
dom.style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-dom.offsetHeight)+'px';
num++;
document.title=num;
//if(num>1000){num=0;clearInterval(timeID);}
},100);
}
setPos();
//window.onscroll=window.onresize=setPos;
既然fixed浏览器已经实现,真的就没办法模拟出来吗?!!<div style="width:100%;height:2000px;border:1px red solid;"></div>
<div id="test" style="position:absolute;left:50px;top:0px;background:url(http://avatar.profile.csdn.net/F/4/2/2_gkw521.jpg);width:100px;height:100px;"></div>
<script>
var dom=document.getElementById('test');
var =true,timeID,num=0;;
var setPos=function(){
f=false;
clearInterval(timeID);
timeID=setInterval(function(){
dom.style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-dom.offsetHeight)+'px';
num++;
document.title=num;
//if(num>1000){num=0;clearInterval(timeID);}
},100);
}
setPos();
//window.onscroll=window.onresize=setPos;
参考
楼上全是基于CSS的,我需要的是JS模拟,而且div中含有图片。真的无法实现吗?
但是在网站已经做好情况下可能会影响原有的css。楼主这个代码是不是没贴全?