一个JS特效(随滚动条滚动)有时可以,有时无效的疑问
一个朋友使用动网的论坛,想在论坛上添加一个随滚动条滚动的图片(有链接),可是在有些电脑上就能有这个效果,在有些上只有刚打开这个页面才有,一拉动滚动条,这个跟随的图片就消失了,滚动效果的代码如下:
<script language="JavaScript">
<!-- Written by Myhyli, 2003/07/21. myhyli.blueidea.com -->
<!-- Member Of Blueidea Web Team. -->
<!-- Welcome to www.blueidea.com. -->
var delta=0.15
var collection;
function floaters() {
this.items = [];
this.addItem = function(id,x,y,content)
{
document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
var newItem = {};
newItem.object = document.getElementById(id);
newItem.x = x;
newItem.y = y;
this.items[this.items.length] = newItem;
}
this.play = function()
{
collection = this.items
setInterval('play()',10);
}
}
function play()
{
if(screen.width<=800)
{
for(var i=0;i<collection.length;i++)
{
collection[i].object.style.display = 'no';
}
return;
}
for(var i=0;i<collection.length;i++)
{
var followObj = collection[i].object;
var followObj_x = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
var followObj_y = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);
if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
followObj.style.left=followObj.offsetLeft+dx;
}
if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
followObj.style.top=followObj.offsetTop+dy;
}
followObj.style.display = '';
}
}
var theFloaters = new floaters();
theFloaters.addItem('followDiv1','document.body.clientWidth-106',80,'<a href=http://www.56hx.com target=_blank><img src=../img/bbs-1.gif border=0></a><br><a href=http://www.56hx.com/wlinfo/index.asp target=_blank><img src=../img/bbs-2.gif border=0></a><br><a href=http://www.56hx.com/cllm/index.asp target=_blank><img src=../img/bbs-3.gif border=0></a><br><a href=http://www.56hx.com/job/index.asp target=_blank><img src=../img/bbs-4.gif border=0></a><br><a href=http://www.56hx.com/wlsb/index.asp target=_blank><img src=../img/bbs-5.gif border=0></a><br><a href=http://www.56hx.com/tcps/index.asp target=_blank><img src=../img/bbs-6.gif border=0></a><br><a href=http://www.56hx.com/huangye/index.asp target=_blank><img src=../img/bbs-7.gif border=0></a>');
theFloaters.play();
</script>
具体的地址在www.56hx.com.cn/56bbs/, 他让我帮忙看问题在哪里,我看了一下没看出来,请教大家,是不是跟浏览器版本、分辨率有关系,还是跟操作系统有关系,多谢!
<script language="JavaScript">
<!-- Written by Myhyli, 2003/07/21. myhyli.blueidea.com -->
<!-- Member Of Blueidea Web Team. -->
<!-- Welcome to www.blueidea.com. -->
var delta=0.15
var collection;
function floaters() {
this.items = [];
this.addItem = function(id,x,y,content)
{
document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
var newItem = {};
newItem.object = document.getElementById(id);
newItem.x = x;
newItem.y = y;
this.items[this.items.length] = newItem;
}
this.play = function()
{
collection = this.items
setInterval('play()',10);
}
}
function play()
{
if(screen.width<=800)
{
for(var i=0;i<collection.length;i++)
{
collection[i].object.style.display = 'no';
}
return;
}
for(var i=0;i<collection.length;i++)
{
var followObj = collection[i].object;
var followObj_x = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
var followObj_y = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);
if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
followObj.style.left=followObj.offsetLeft+dx;
}
if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
followObj.style.top=followObj.offsetTop+dy;
}
followObj.style.display = '';
}
}
var theFloaters = new floaters();
theFloaters.addItem('followDiv1','document.body.clientWidth-106',80,'<a href=http://www.56hx.com target=_blank><img src=../img/bbs-1.gif border=0></a><br><a href=http://www.56hx.com/wlinfo/index.asp target=_blank><img src=../img/bbs-2.gif border=0></a><br><a href=http://www.56hx.com/cllm/index.asp target=_blank><img src=../img/bbs-3.gif border=0></a><br><a href=http://www.56hx.com/job/index.asp target=_blank><img src=../img/bbs-4.gif border=0></a><br><a href=http://www.56hx.com/wlsb/index.asp target=_blank><img src=../img/bbs-5.gif border=0></a><br><a href=http://www.56hx.com/tcps/index.asp target=_blank><img src=../img/bbs-6.gif border=0></a><br><a href=http://www.56hx.com/huangye/index.asp target=_blank><img src=../img/bbs-7.gif border=0></a>');
theFloaters.play();
</script>
具体的地址在www.56hx.com.cn/56bbs/, 他让我帮忙看问题在哪里,我看了一下没看出来,请教大家,是不是跟浏览器版本、分辨率有关系,还是跟操作系统有关系,多谢!
...全文
相关推荐
html5极酷滚动条3D特效
国外超炫3D滚动条拉动特效,有翻转,旋转,波浪……总共12款炫酷html5特效免积分赠送
实现渐变和图形背景滚动效果的 jQuery 和 JavaScript
在本篇文章中,我们将介绍如何使用 jQuery 和 JavaScript 来实现渐变和图形背景滚动效果。我们将提供相应的源代码供您参考和使用。
基于vue实现滚动条滚动到指定位置对应位置数字进行tween特效
主要介绍了基于vue实现滚动条滚动到指定位置对应位置数字进行tween特效,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
JS控制滚动条自动向下滚动
JS 类似BBS控制输入框输入信息后,滚动条自动滚到最下方,始终显示最后输入的一条信息,在做BBS的兄弟,可以参考一下思想
js实现滚动条滚动到页面底部继续加载
这个实例应该说可以很简单,直接使用jQuery的方法来处理也是可以的。但本文底层使用原生的js来处理,遇到一些小知识点可以分析一下也算有所得。 原理很简单,就是为window添加一个scroll事件,浏览器每次触发scroll事件时判断是否滚动到了浏览器底部,如果到了底部则加载新数据。关键是计算滚动条是否滚动到了浏览器底部,算法如下 滚动条卷起来的高度 + 窗口高度 > 文档的总高度 + 50/*我这里将滚动响应区域高度取50px*/;如果这个判断为true则表示滚动条滚动到了底部。 实例 <style type="text/css"> html,body, div, dl, dt, d


