兼容ie6 7 8 ,ff3.5 3.6,chrome 4.1.2,safari
重新修正
1.滚动时抖动的问题,主要体现在ff3.6上
2.加入了ie6下的固定
3.分成了两个块,xhtml,html解析
4.随着屏幕大小而变动
兼容ie6 7 8
ff3.5 3.6
chrome 4.1.2
safari
xhtml1.0解析
html,body{
padding:0;
margin:0;
}
我在随平滚
我静止不动
function scrollx(p){
var d = document,dd = d.documentelement,db = d.body,w = window,o = d.getelementbyid(p.id),ie6 = /msie 6/i.test(navigator.useragent),style,timer;
if(o){
o.style.csstext +=";position:"+(p.f&&!ie6?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0');
if(p.f&&ie6){
o.style.csstext +=';left:expression(documentelement.scrollleft + '+(p.l==undefined?dd.clientwidth-o.offsetwidth:p.l)+' + "px");top:expression(documentelement.scrolltop +'+(p.t==undefined?dd.clientheight-o.offsetheight:p.t)+'+ "px" );';
dd.style.csstext +=';background-image: url(about:blank);background-attachment:fixed;';
}else{
if(!p.f){
w.onresize = w.onscroll = function(){
clearinterval(timer);
timer = setinterval(function(){
//双选择为了修复chrome 下xhtml解析时dd.scrolltop为 0
var st = (dd.scrolltop||db.scrolltop),c;
c = st - o.offsettop + (p.t!=undefined?p.t:(w.innerheight||dd.clientheight)-o.offsetheight);
if(c!=0){
o.style.top = o.offsettop + math.ceil(math.abs(c)/10)*(c<0?-1:1) + 'px';
}else{
clearinterval(timer);
}
},10)
}
}
}
}
}
scrollx({
id:'aa'
})
scrollx({
id:'bb',
l:0,
t:200,
f:1
})
/*
id 你要滚动的内容的id
l 横坐标的位置 不写为紧贴右边
t 你要放在页面的那个位置默认是贴着底边 0是贴着顶边
f 1表示固定 不写或者0表示滚动
*/
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]
html4.01解析
html,body{
padding:0;
margin:0;
}
我在随平滚
我静止不动
function scroll(p){
var d = document,dd = d.documentelement,db = d.body,w = window,o = d.getelementbyid(p.id),ie = /msie/i.test(navigator.useragent),style,timer;
if(o){
//ie8下position:fixed下top left失效
o.style.csstext +=";position:"+(p.f&&!ie?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0');
if(p.f&&ie){
o.style.csstext +=';left:expression(body.scrollleft + '+(p.l==undefined?db.clientwidth-o.offsetwidth:p.l)+' + "px");top:expression(body.scrolltop +'+(p.t==undefined?db.clientheight-o.offsetheight:p.t)+'+ "px" );'
db.style.csstext +=";background-image:url(about:blank);background-attachment:fixed;"
}else{
if(!p.f){
w.onresize = w.onscroll = function(){
clearinterval(timer);
timer = setinterval(function(){
var st = db.scrolltop,c;
c = st - o.offsettop + (p.t!=undefined?p.t:(w.innerheight||db.clientheight)-o.offsetheight);
if(c!=0){
o.style.top = o.offsettop + math.ceil(math.abs(c)/10)*(c<0?-1:1) + 'px';
}else{
clearinterval(timer);
}
},10)
}
}
}
}
}
scroll({
id:'aa'
})
scroll({
id:'bb',
l:0,
t:200,
f:1
})
/*
id 你要滚动的内容的id
l 横坐标的位置 不写为紧贴右边
t 你要放在页面的那个位置默认是贴着底边 0是贴着顶边
f 1表示固定 不写或者0表示滚动
*/
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]