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二次开发,实现通过鼠标点击页面任何区域,聚焦当前点击位置 ...
随机推荐
- ios音频视频资料--备用
视频播放 MediaPlayer.framework MPMoviePlayerViewController VS MPMoviePlayerController MPMoviePlayerViewC ...
- java Scanner与BufferedReader读取键盘输入性能比较
java Scanner与BufferedReader读取键盘输入性能比较 1.Scanner和BufferedReader 性能比较 在java中常见的从键盘获取输入的方式有 ...
- PYTHON多进程样码
敲了一晚上,留个念想. 发现它和LINUX的C编程差不多,就是作了PYTHON化的语法封装. 以后希望有机会能用上.. A,多进程函数化实现 import multiprocessing import ...
- TC SRM 607 DIV2
求拼接完成后的字符串包含的子回文串的数目,一开始还用暴力去做,想都不用想 肯定超时了. 复习了一下求最长子回文串的算法,发现可以类似解决. 给相邻字符之间添加一个'@'字符,这样所有的回文串都是奇数长 ...
- 使用Mybatis Generator自动生成Mybatis相关代码
本文将简要介绍怎样利用Mybatis Generator自动生成Mybatis的相关代码: 一.构建一个环境: 1. 首先创建一个表: CREATE TABLE pet (name VARCHAR(2 ...
- 给自己加油,一定要学会MFC!
我自己对于没有学会MFC始终耿耿于怀,都什么时代了啊,但是我仍然坚持会去学MFC,因为MFC虽然落后与复杂,但是在Windows平台上仍然是无所不能的(其实Windows平台仍然是唯一可以赚钱的平台, ...
- Spring cloud项目实践(一)
链接地址:http://sail-y.github.io/2016/03/21/Spring-cloud%E9%A1%B9%E7%9B%AE%E5%AE%9E%E8%B7%B5/ 什么是Spring ...
- Http Get Post put delete
HTTP POST GET 本质区别详解一 原理区别 一般在浏览器中输入网址访问资源都是通过GET方式:在FORM提交中,可以通过Method指定提交方式为GET或者POST,默认为GET提交 Htt ...
- URI Scheme
1. 什么是URI Scheme? 一般情况下,遇到这种概念不清的问题,最好的第一手资料就是wiki,实在看不懂,再看百度百科,但前者给出的资料一般都是更加准确一些. 以下为维基百科和百度百科关于这个 ...
- Redis 如何导出数据
Redis是一款支持多种数据类型的Key-Value数据库. 这里介绍下如何从Redis中导出数据. 数据是如何存储的?. Redis中是把数据保存到内存中的,但是它也会定期的把数据写会到硬盘中. R ...