自己写的一个div随页面滚动的效果
2013-12-11 13:25
274 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
html,body{
padding:0;
margin:0;
}
</style>
</head>
<body>
<div id="aa" style="width:200px;height:200px;background:#c0c0c0;" >我跟随屏幕滚动</div>
<div id="bb" style="width:200px;height:200px;background:#c0c0c0;" >我是固定不会动</div>
<div style="width:100%;height:500px;background:#000"></div>
<div style="width:100%;height:500px;background:green"></div>
<div style="width:100%;height:500px;background:red"></div>
</body>
</html>
<script>
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;
if(o){
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(){
var timer,timer1;
return function(){
if(timer)
clearTimeout(timer);
timer = setTimeout(function(){
timer1 = 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(timer1);
}
},10)
},100)//控制滚动的频率越大频率越慢
}
}()
}
}
}
}
scroll({
id:'aa'
})
scroll({
id:'bb',
l:0,
t:200,
f:1
})
</script><br />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
html,body{
padding:0;
margin:0;
}
</style>
</head>
<body>
<div id="aa" style="width:200px;height:200px;background:#c0c0c0;" >我跟随屏幕滚动</div>
<div id="bb" style="width:200px;height:200px;background:#c0c0c0;" >我是固定不会动</div>
<div style="width:100%;height:500px;background:#000"></div>
<div style="width:100%;height:500px;background:green"></div>
<div style="width:100%;height:500px;background:red"></div>
</body>
</html>
<script>
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;
if(o){
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(){
var timer,timer1;
return function(){
if(timer)
clearTimeout(timer);
timer = setTimeout(function(){
timer1 = 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(timer1);
}
},10)
},100)//控制滚动的频率越大频率越慢
}
}()
}
}
}
}
scroll({
id:'aa'
})
scroll({
id:'bb',
l:0,
t:200,
f:1
})
</script><br />
相关文章推荐
- 让一个div不随页面滚动
- 如何css做一个点击导航 页面滚动, 并且有动画效果
- 自己整理一个div的jquery弹窗效果
- 如何css做一个点击导航 页面滚动, 并且有动画效果
- 网页上右边有一个微信二维码随着页面滚动而不动的效果
- jquery的动画效果animate附加一个滚动回到页面的例子
- 滚动新闻效果(使一个div滚动)
- 分享一个自己利用javascript中的window.setInterval()定时器实现页面背景图片淡入淡出效果
- jQuery实现div浮动层跟随页面滚动效果
- 分享一个自己利用javascript中的window.setInterval()定时器实现页面背景图片变换的特效(同时淡入淡出效果)
- jQuery实现div浮动层跟随页面滚动效果
- DIV+CSS结合js控制页面滚动的效果
- 在iframe里的页面编写js,实现在父窗口上创建动画效果展开和收缩的div(不变动iframe父窗口代码)
- 由于设计页面需要,要把两个并排显示的 div 实现一样高的效果, n 行 n 列布局,每列高度(事先并不能确定哪列的高度)相同,每个设计师追求的目标。方法有以下几种: 1 JS 实现(判断 2 个 d
- 【转】 div+css的图片滚动效果
- 一个DIV+CSS导航条效果
- velocity.js实现页面滚动切换效果
- jquery实现的一个导航滚动效果具体代码
- js+div实现文字滚动和图片切换效果代码
- 一个div中许多列表,使用全局,将数据显示到页面