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二次开发,实现通过鼠标点击页面任何区域,聚焦当前点击位置 ...
随机推荐
- Android 虚拟机Dalvik、Android各种java包功能、Android相关文件类型、应用程序结构分析、ADB
Android虚拟机Dalvik Dalvik冲击 随着Google 的AndroidSDK 的发布,关于它的API 以及在移动电话领域所带来的预期影响这些方面的讨论不胜枚举.不过,其中的一个话题在J ...
- 从内部剖析C# 集合之--Dictionary
Dictionary和hashtable用法有点相似,他们都是基于键值对的数据集合,但实际上他们内部的实现原理有很大的差异, 先简要概述一下他们主要的区别,稍后在分析Dictionary内部实现的大概 ...
- 关联规则算法Apriori的学习与实现
转自关联规则算法Apriori的学习与实现 首先我们来看,什么是规则?规则形如"如果-那么-(If-Then-)",前者为条件,后者为结果.关联规则挖掘用于寻找给定数据集中项之间的 ...
- The working copy at 'xxx' is too old 错误解决
使用svn update更新时候提示: svn: E155036: The working copy at 'xxx' is too old (format 29) to work with clie ...
- jsp空页面导致的jvm heap溢出
为了性能测试需要,写一个了简单的jsp页面: <%@ page contentType="text/html;charset=UTF-8" language="ja ...
- 135. Candy
题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...
- 浏览器助手,请求拦截,后台模拟键鼠操作,页内嵌入JS
http://www.cnblogs.com/ /// <summary> /// 网页浏览器助手 /// 请求拦截,后台模拟键鼠操作,页内嵌入JS ...
- tlplayer for ios V1.1(附上截图)
此程序UI修改于虎跃在线课堂.所以极其相似. 可以播放网络视频与本地视频,不知道怎么拷贝本地视频到Ipad或iphone上看的朋友,请自己到网上看教程. 支持mms,file,rtsp,rtmp,ht ...
- CSS选择器一览
CSS选择器一览 CSS3 选择器 在 CSS 中,选择器是一种模式,用于选择需要添加样式的元素. "CSS" 列指示该属性是在哪个 CSS 版本中定义的.(CSS1.CSS2 还 ...
- easyui datagrid隔行变色
属性striped设置为true,即striped:true. 如果想更改颜色,可以更改easyui.css中的.datagrid-row-alt样式.