js 小技巧 鼠标跟随图片特效
来源:互联网 发布:mysql 根据某字段排序 编辑:程序博客网 时间:2024/04/30 02:45
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>跟随鼠标的图片效果-懒人图库</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.lanrentuku.com/down/js/images/12492980870.jpg"></div>
<div class="thumb"><img alt="" src="http://www.lanrentuku.com/down/js/images/12492980871.jpg"></div>
<p style="color:#FFFFFF">查找更多代码,请访问:<a href="http://www.lanrentuku.com" target="_blank">懒人图库</a></p>
</body>
</html>
- js 小技巧 鼠标跟随图片特效
- js小技巧 鼠标跟随图片
- js 鼠标跟随小例子
- DOM特效之鼠标更换图片和鼠标跟随
- 鼠标跟随提示特效
- JS实现图片跟随鼠标移动
- JS特效--跟随鼠标移动的日历时钟
- 网页图片特效小技巧
- 网页图片特效小技巧
- IE浏览器下的JS鼠标特效(文本跟随鼠标环绕的特效)
- [js小技巧]鼠标移到图片高亮度显示
- js 鼠标放置图片展示大图并跟随鼠标移动
- js实现鼠标移入移出小特效!
- js特效 随鼠标出现的图片
- 跟随鼠标图片
- 图片跟随鼠标移动
- 图片跟随鼠标
- 图片跟随鼠标偏移
- Android NDK 概览
- js小技巧 实现字体大中小的另一种方法
- 【Machine Learning】最近做的若干实验的总结
- 第十六周第三天
- 第十六周第三天
- js 小技巧 鼠标跟随图片特效
- Ajax实现异步交互完成注册页面
- 第十六周第四天
- JS小技巧 网页随即显示名人名言
- 程序员那点迷惘事
- 第十六周第五天
- js小技巧 用js写漂亮的日历
- PostgreSQL之精妙的数据库导入导出工具架构 (十一)
- web.xml之context-param与init-param的区别与作用