jQuery获取鼠标移动方向
<!doctype html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> | |
<meta name="Generator" content="EditPlus®"> | |
<meta name="Author" content=""> | |
<meta name="Keywords" content=""> | |
<meta name="Description" content=""> | |
<title>Demo</title> | |
<style> | |
* { | |
margin: 0; | |
padding: 0; | |
} | |
ul, | |
li { | |
list-style: none; | |
} | |
div { | |
font-family: "Microsoft YaHei"; | |
} | |
html, | |
body { | |
width: 100%; | |
height: 100%; | |
background: #f2f2f2; | |
} | |
ul { | |
margin-left: 50px; | |
} | |
ul li { | |
float: left; | |
} | |
ul li .outer { | |
width: 300px; | |
height: 250px; | |
} | |
ul li .outer .inner { | |
width: 300px; | |
height: 250px; | |
background: rgba(0, 0, 0, .3); | |
} | |
</style> | |
<script src="http://www.jq22.com/jquery/1.11.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<ul> | |
<li> | |
<div class="outer"> | |
<img src="img/a1.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
<li> | |
<div class="outer"> | |
<img src="img/a2.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
<li> | |
<div class="outer"> | |
<img src="img/a3.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
<li> | |
<div class="outer"> | |
<img src="img/a4.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
<li> | |
<div class="outer"> | |
<img src="img/a5.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
<li> | |
<div class="outer"> | |
<img src="img/a6.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
<li> | |
<div class="outer"> | |
<img src="img/a7.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
<li> | |
<div class="outer"> | |
<img src="img/a8.png" width="300px" height="250px" /> | |
<div class="inner"> | |
这是描述。。。 | |
</div> | |
</div> | |
</li> | |
</ul> | |
<script> | |
; | |
(function($) { | |
$.fn.extend({ | |
show: function(div) { | |
var w = this.width(), | |
h = this.height(), | |
xpos = w / 2, | |
ypos = h / 2, | |
eventType = "", | |
direct = ""; | |
this.css({ | |
"overflow": "hidden", | |
"position": "relative" | |
}); | |
div.css({ | |
"position": "absolute", | |
"top": this.width() | |
}); | |
this.on("mouseenter mouseleave", function(e) { | |
var oe = e || event; | |
var x = oe.offsetX; | |
var y = oe.offsetY; | |
var angle = Math.atan((x - xpos) / (y - ypos)) * 180 / Math.PI; | |
if (angle > -45 && angle < 45 && y > ypos) { | |
direct = "down"; | |
} | |
if (angle > -45 && angle < 45 && y < ypos) { | |
direct = "up"; | |
} | |
if (((angle > -90 && angle < -45) || (angle > 45 && angle < 90)) && x > xpos) { | |
direct = "right"; | |
} | |
if (((angle > -90 && angle < -45) || (angle > 45 && angle < 90)) && x < xpos) { | |
direct = "left"; | |
} | |
move(e.type, direct) | |
}); | |
function move(eventType, direct) { | |
if (eventType == "mouseenter") { | |
switch (direct) { | |
case "down": | |
div.css({ | |
"left": "0px", | |
"top": h | |
}).stop(true, true).animate({ | |
"top": "0px" | |
}, "fast"); | |
break; | |
case "up": | |
div.css({ | |
"left": "0px", | |
"top": -h | |
}).stop(true, true).animate({ | |
"top": "0px" | |
}, "fast"); | |
break; | |
case "right": | |
div.css({ | |
"left": w, | |
"top": "0px" | |
}).stop(true, true).animate({ | |
"left": "0px" | |
}, "fast"); | |
break; | |
case "left": | |
div.css({ | |
"left": -w, | |
"top": "0px" | |
}).stop(true, true).animate({ | |
"left": "0px" | |
}, "fast"); | |
break; | |
} | |
} else { | |
switch (direct) { | |
case "down": | |
div.stop(true, true).animate({ | |
"top": h | |
}, "fast"); | |
break; | |
case "up": | |
div.stop(true, true).animate({ | |
"top": -h | |
}, "fast"); | |
break; | |
case "right": | |
div.stop(true, true).animate({ | |
"left": w | |
}, "fast"); | |
break; | |
case "left": | |
div.stop(true, true).animate({ | |
"left": -w | |
}, "fast"); | |
break; | |
} | |
} | |
} | |
} | |
}); | |
})(jQuery) | |
/* | |
*使用说明: | |
* $(".a").show($(".b")) | |
* a是展示层,b是遮罩层 | |
* b在a的内部 | |
*/ | |
$(".outer").each(function(i){ | |
$(this).show($(".inner").eq(i)); | |
}); | |
</script> | |
</body> | |
</html> | |
jQuery获取鼠标移动方向的更多相关文章
- jQuery获取鼠标移动方向2
(function($) { $.fn.extend({ show: function(div) { var w = this.width(), h = this.height(), xpos = w ...
- 利用jQuery获取鼠标当前的坐标
文字来源:http://www.smalluv.com/jquery_code_106.html jQuery获取当前鼠标坐标位置: <div id="testDiv"> ...
- jquery 获取鼠标位置
//获取鼠标位置 $(function(){ $('body').mousemove(function(e) { e = e || window.event; __xx = e.pageX || e. ...
- jquery 获取鼠标和元素的坐标点
获取当前鼠标相对img元素的坐标 $('img').mousemove(function(e) { varpositionX=e.pageX-$(this).offset().left; //获取当前 ...
- jQuery获取鼠标事件源(万能)
//任意位置 $(document).ready(function(){ $(document).click(function(){ $("#id_").hide(); }); } ...
- jquery 获取鼠标坐标
$("#x").text(event.pageX), $("#y").text(event.pageY);
- jq获取鼠标位置
jq获取鼠标位置 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- JQuery获取与设置HTML元素的值value
JQuery获取与设置HTML元素的值value 作者:简明现代魔法图书馆 发布时间:2011-07-07 10:16:13 20481 次阅读 服务器君一共花费了13.221 ms进行了6次数据库查 ...
- jquery实现鼠标焦点十字效果
系统开发时很多地方需要有焦点效果,例如:鼠标点击聚焦,地图定位,在图片上突出显示,焦点定位页面元素. 本小功能通过jquery和graphics二次开发,实现通过鼠标点击页面任何区域,聚焦当前点击位置 ...
随机推荐
- Jquery animate的使用方法
js: $('#colspan').click(function () { if ($('#colspan').hasClass('glyphicon-chevron-up')) { $('#cols ...
- 开发错误日志之FTP协议传输文件问题
从开发端用FTP协议向服务器(Linux系统)传输文件时,cat -A查询文件内容中行尾会有^M出现. 解决方案:改用SFTP协议上传文件.
- 【产品体验】eyepetizer开眼
第一次写博客,内心还有点小激动呢~~本人产品新人,学习中,希望大家多多指教! 先来两张开眼的界面图坐镇—— 开眼简介: appetizer for eyes 即 eyepetizer ...
- 第九章 Mass Storage设备
9.1 Mass Storage设备介绍 USB的Mass Storage类是USB大容量储存设备类(Mass Storage Device Class).专门用于大容量存储设备,比如U盘.移动硬盘. ...
- 【Linux安全】chattr命令锁定账户敏感文件
有时候你发现用root权限都不能修改某个文件,大部分原因是曾经用chattr命令锁定该文件了.chattr命令的作用很大,其中一些功能是由Linux内核版本来支持的,不过现在生产绝大部分跑的linux ...
- spring声明式事务 同一类内方法调用事务失效
只要避开Spring目前的AOP实现上的限制,要么都声明要事务,要么分开成两个类,要么直接在方法里使用编程式事务 [问题] Spring的声明式事务,我想就不用多介绍了吧,一句话“自从用了Spring ...
- iOS上获得MAC地址
很多时候我们都需要唯一来确定一台设备,苹果设备本来有个UDID号,可以实现这个目的.在iOS5.0以前,还有一个uniqueIdentifier的API用来获得这个number.不过iOS5之后,这个 ...
- udelay、mdelay、ndelay、msleep使用比较说明
时间单位: 毫秒(ms).微秒 (μs).纳秒(ns).皮秒(ps).飞秒(fs).阿秒.渺秒 1 s = 10^3 ms = 10^6 us = 10^9 ns = 10^12 ps = ...
- BMS 项目过程中遇到的问题
环境搭建的问题 Git的ssh私人密钥问题, 路劲不正确的话使用ssh方式连接github进行远程push或clone会出现需要输入密码而怎么输入都不正确的情况,这个时候使用下面的办法: http方面 ...
- ERP 实施和应用不成功共同点
ERP 实施和应用不成功共同点 ERP 重新得到人们理性的关注并不意味着实施和应用ERP变得轻而易举了.如何才能实施好ERP?这仍然是关键的问题. 大部份企业应用ERP不成功的原因是什么,许多 ...