html 滚动固定显示js脚本
<script type="text/javascript">
function htmlScroll()
{
var
top = document.body.scrollTop ||
document.documentElement.scrollTop;
if(elFix.data_top <
top)
{
elFix.style.position = ‘fixed‘;
elFix.style.top =
0;
elFix.style.left =
elFix.data_left;
}
else
{
elFix.style.position =
‘static‘;
}
}
function htmlPosition(obj)
{
var o = obj;
var t =
o.offsetTop;
var l = o.offsetLeft;
while(o =
o.offsetParent)
{
t += o.offsetTop;
l +=
o.offsetLeft;
}
obj.data_top = t;
obj.data_left = l;
}
var oldHtmlWidth = document.documentElement.offsetWidth;
window.onresize =
function(){
var newHtmlWidth =
document.documentElement.offsetWidth;
if(oldHtmlWidth ==
newHtmlWidth)
{
return;
}
oldHtmlWidth =
newHtmlWidth;
elFix.style.position =
‘static‘;
htmlPosition(elFix);
htmlScroll();
}
window.onscroll =
htmlScroll;
var elFix = document.getElementById(‘div1‘);
htmlPosition(elFix);
</script>
以上就是固定显示的一下记录
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。