欢迎您来到网页代码站!
设为首页
加入收藏
留 言 板
精品美文
在线手册
如果您关闭了浏览器的javascript,可能导致页面部分功能无法显示,请开启javascript以便正常浏览本网页。网页代码站(www.webdm.cn)谢谢您的支持!
代码首页
菜单导航
表格相关
表单及按钮
层和布局
计算转换
游戏娱乐
广告代码
图片特效
浏览器相关
日期时间
背景特效
文本链接
按标题搜索
按内容搜索
热搜:
div
css
推荐
js
菜单
广告
flash
TAB
时间
焦点图
布局
按钮
您的当前位置:
网页代码站
>>
图片特效
>> 【荐】JS+CSS实现的鼠标控制小球特效
【荐】JS+CSS实现的鼠标控制小球特效
分类:
图片特效
时间:2010-08-08 点击:
关键词:
JS
|
css
|
网页代码
|
代码
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>【荐】JS+CSS实现的鼠标控制小球特效 - www.webdm.cn</title> <style type="text/css"> body { margin: 0px; padding: 0px; background: #000; position: absolute; width: 100%; height: 100%; } .thumb { position: relative; float: left; display: block; width: 47%; height: 46%; margin-left: 2%; margin-top: 2%; overflow: hidden; cursor: crosshair; } .thumb img { position: absolute; } </style> <script type="text/javascript"> var thu = []; function run(){ for (var i in thu) thu[i].scroll(); setTimeout(run, 16); } function scroll(){ var div = document.body.getElementsByTagName('div'); for(var i = 0, n = div.length; i < n; i++) { var o = div[i]; if (o.className.indexOf('thumb') >= 0) { thu.push(o); o.img = o.getElementsByTagName('img')[0]; o.nwi = o.img.width; o.nhi = o.img.height; o.img = o.img.style; o.x0 = 0; o.y0 = 0; o.xm = 0; o.ym = 0; o.onmousemove = function (e) { if (window.event) e = window.event; this.xm = e.clientX; this.ym = e.clientY; } o.scroll = function () { var xmo = Math.min(this.nw, Math.max(0, this.xm - this.nx)); var ymo = Math.min(this.nh, Math.max(0, this.ym - this.ny)); var x = -xmo * (this.nwi / this.nw) + xmo; var y = -ymo * (this.nhi / this.nh) + ymo; this.x0 += ((this.x0 > x) ? -1 : 1) * Math.abs(this.x0 - x) * .1; this.y0 += ((this.y0 > y) ? -1 : 1) * Math.abs(this.y0 - y) * .1; this.img.left = ''.concat(Math.round(this.x0), 'px'); this.img.top = ''.concat(Math.round(this.y0), 'px'); } o.onresize = function () { this.nx = 0; this.ny = 0; this.nw = this.offsetWidth; this.nh = this.offsetHeight; for (var o = this; o != null; o = o.offsetParent) this.nx += o.offsetLeft, this.ny += o.offsetTop; } o.onresize(); } } run(); } onload = function() { scroll(); } </script> </head> <body> <div class="thumb"><img alt="" src=" http://www.webdm.cn/images/20100808/12492980870.jpg"></div> <div class="thumb"><img alt="" src=" http://www.webdm.cn/images/20100808/12492980871.jpg"></div> <br /> <p><a href="http://www.webdm.cn">网页代码站</a> - 最专业的代码下载网站 - 致力为中国站长提供有质 量的代码!</p> </body> </html>
运行代码
全选代码
复制代码
保存代码
友情提示
【荐】JS+CSS实现的鼠标控制小球特效,很有立体真实感。
一、如果您使用的浏览器版本为IE6.0、360浏览器V3.0.8.1版本或者IE的更低版本浏览本页面,建议您升级浏览器至IE7以上,上面的“运行”按钮可能不能用,但您可按以下方式查看。
运行代码方式:
1、点击“复制”按钮;
2、在桌面建立一个txt文档;
3、粘贴复制的代码;
4、最后把txt的扩展名改为“htm”或“html”;
5、完成,打开即可看到效果。
二、如果您使用FireFox或者非IE浏览器,建议您使用IE7以上版本。上面的“复制”按钮失效,请您“全选”,以普通方式复制!
三、某些代码因需加载完Jquery等之类比较大的JS文件,如果您看不到效果,请您刷新页面!
四、某些代码不能完全兼容各浏览器,还请您再次修改才能使用!给您带来的不便!尽请谅解!谢谢您的支持!
来顶一下
上一篇:
JS算算以后的时间
下一篇:
光标选择输入框
JS图片切换特效
完全利用CSS实现图片切换特效
防腾讯网的JS图片切换代码
常用JS图片滚动(无缝、平滑、
JS防阿里妈妈的图片幻灯片代码
JavaScript+Flash制作常用的焦点图
js图片渐隐渐现特效
JavaScript实现很漂亮的开花特效
JS点击小图显示大图的代码
CSS实现的鼠标点击小图无刷新放
问问
|
贴吧
|
查询
|
给我留言
|
精品美文
|
友情链接
| |
本站承接网站开发业务
版权声明
|
广告服务
|
联系我们
|
网站地图
|
关于我们
| |
滇ICP备08101440号
Powered by
网页代码站
(网页即"web" + 代码即"dm" + "cn" = webdm.cn) | 最专业的代码下载网站 - 致力为中国站长提供高质量的代码!