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二次开发,实现通过鼠标点击页面任何区域,聚焦当前点击位置 ...
随机推荐
- hdu 3303 Harmony Forever (线段树 + 抽屉原理)
http://acm.hdu.edu.cn/showproblem.php?pid=3303 Harmony Forever Time Limit: 20000/10000 MS (Java/Othe ...
- PPTPD/L2TP/IPSec VPN一键安装包 For CentOS 6
一.一键安装PPTPD VPN 本教程适用于Openv VPS.Xen VPS或者KVM VPS. 1.首先运行如下命令: cat /dev/net/tun 返回的必须是: cat: /dev/net ...
- SQL中not and or优先级问题
SQL中 not and or优先级问题 刚刚在项目中遇到这样一个问题,SQL语句如下: 我想要的结果的条件是:1. LIBRARY_ID=1 或者 LIB_ID=1 2.STATUS=3 但是结果 ...
- [转].NET程序在windows操作系统上独立运行的技术要点
发现一个不错的网站,转载一篇文章方便查看 转自 http://www.linuxdot.net/bbsfile-3354 ===================================== ...
- 388A Fox and Box Accumulation
一开始贪心策略想错了! #include<cstdio> #include<algorithm> using namespace std; ]; int main() { in ...
- ORMBase对象/关系型数据库映射在MVC中的应用(二)
3.DataBase基类,查询方法返回值是List<T>,并且是分页的,ThePart.dll版本2.0中封装了一个PageInfo类,作为分页的类型.这种方法很机械,也很狗血..建议大家 ...
- Yorhom浅谈:作为一名初中生,自学编程的点点滴滴 - Yorhom's Game Box
Yorhom浅谈:作为一名初中生,自学编程的点点滴滴 我是一名不折不扣的初中生,白天要背着书包去上学,晚上要拿起笔写作业.天天如此,年年如此. 我的爱好很广泛,喜欢了解历史,读侦探小说,骑车,打篮球, ...
- Yii url createUrl redirect相关
一篇文章: 在yii中明明白白生成网址: 在Yii中经常要生成URL,不管是为了自动跳转还是仅仅是一个链接.下面对Yii中的URL生成做了一个总结.提示:以下controllerX代表控制器X,act ...
- Android 内核初识(3)init进程
init是一个进程,确切地说,它是Linux系统中用户空间的第一个进程.由于Android是基于Linux内核的,所以init也是Android系统中用户空间的第一个进程,它的进程号是1.作为天字第一 ...
- [NYOJ 43] 24 Point game
24 Point game 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 There is a game which is called 24 Point game ...