写的不够高大上 , 不要介意哦。。。

Js:

//进去
$(".flash").bind("mouseenter",function(e){ /** the width and height of the current div **/
var w = $(this).width();
var h = $(this).height(); /** calculate the x and y to get an angle to the center of the div from that x and y. **/
/** gets the x value relative to the center of the DIV and "normalize" it **/
var x = (e.pageX - this.offsetLeft - (w/)) * ( w > h ? (h/w) : );
var y = (e.pageY - this.offsetTop - (h/)) * ( h > w ? (w/h) : ); /** the angle and the direction from where the mouse came in/went out clockwise (TRBL=0123);**/
/** first calculate the angle of the point,
add 180 deg to get rid of the negative values
divide by 90 to get the quadrant
add 3 and do a modulo by 4 to shift the quadrants to a proper clockwise TRBL (top/right/bottom/left) **/
var direction = Math.round((((Math.atan2(y, x) * ( / Math.PI)) + ) / ) + ) % ; /** do your animations here **/
switch(direction) {
case :
$('.showD').css({
'top':'-200px',
'left':'',
'opacity':'',
}).stop().animate({
'top':'',
'left':'',
'opacity':'',
},)
/** animations from the TOP **/
break;
case :
$('.showD').css({
'top':'',
'left':'200px',
'opacity':'',
}).stop().animate({
'top':'',
'left':'',
'opacity':'',
},)
/** animations from the RIGHT **/
break;
case :
$('.showD').css({
'top':'200px',
'left':'',
'opacity':'',
}).stop().animate({
'left':'',
'top':'',
'opacity':'',
},)
/** animations from the BOTTOM **/
break;
case :
$('.showD').css({
'top':'',
'left':'-200px',
'opacity':'',
}).stop().animate({
'left':'',
'right':'',
'opacity':'',
},)
/** animations from the LEFT **/
break; }}); //出来
$(".flash").bind("mouseleave",function(e){ /** the width and height of the current div **/
var w = $(this).width();
var h = $(this).height(); /** calculate the x and y to get an angle to the center of the div from that x and y. **/
/** gets the x value relative to the center of the DIV and "normalize" it **/
var x = (e.pageX - this.offsetLeft - (w/)) * ( w > h ? (h/w) : );
var y = (e.pageY - this.offsetTop - (h/)) * ( h > w ? (w/h) : ); /** the angle and the direction from where the mouse came in/went out clockwise (TRBL=0123);**/
/** first calculate the angle of the point,
add 180 deg to get rid of the negative values
divide by 90 to get the quadrant
add 3 and do a modulo by 4 to shift the quadrants to a proper clockwise TRBL (top/right/bottom/left) **/
var direction = Math.round((((Math.atan2(y, x) * ( / Math.PI)) + ) / ) + ) % ; /** do your animations here **/
switch(direction) {
case :
$('.showD').css({
'right':'',
}).stop().animate({
'right':'',
'top':'-200px',
},)
/** animations from the TOP **/
break;
case :
$('.showD').css({
'top':'',
}).stop().animate({
'top':'',
'left':'200px',
},)
/** animations from the RIGHT **/
break;
case :
$('.showD').css({
'top':'',
'left':'',
}).stop().animate({
'left':'',
'top':'200px',
},)
/** animations from the BOTTOM **/
break;
case :
$('.showD').css({
'top':'',
'left':'',
}).stop().animate({
'left':'-200px',
'right':'',
},)
/** animations from the LEFT **/
break; }});

HTML:

        <div class="flash">
<img class="pic_bg" src="http://img0.imgtn.bdimg.com/it/u=261025820,3584077840&fm=21&gp=0.jpg" style="width:100%;height:100%"/>
<div class="showD">
</div>
</div>

Css:

.flash{
width:200px;
height:200px;
margin-left:%;
background-color:red;
position:relative;
overflow:hidden;
}
.showD{
background: #469acb;
position: absolute;
width:%;
height:200px;
}

JS判断鼠标从哪个方向进入DIV容器的更多相关文章

  1. JS判断鼠标从什么方向进入一个容器

    偶然将想到的一个如何判断鼠标从哪个方向进入一个容器的问题.首先想到的是给容器的四个边添加几个块,然后看鼠标进入的时候哪个块先监听到鼠标事件.不过这样麻烦太多了.google了一下找到了一个不错的解决方 ...

  2. js判断鼠标位置是否在某个div中

    div的onmouseout事件让div消失时,会出现这样的情况,就是当鼠标移至div中的其它内容时,此时也判定为离开div,会触发 onmouseout事件,这样div中的内容就不能操作了.解决的办 ...

  3. js判断鼠标滑轮滚动方向并根据滚动的方向触发不同的事件

    <script> var scrollFunc = function (e) { var direct = 0; e = e || window.event; if (e.wheelDel ...

  4. JS判断鼠标进入容器方向的方法和分析window.open新窗口被拦截的问题

    1.鼠标进入容器方向的判定 判断鼠标从哪个方向进入元素容器是一个经常碰到的问题,如何来判断呢?首先想到的是:获取鼠标的位置,然后经过一大堆的if..else逻辑来确定.这样的做法比较繁琐,下面介绍两种 ...

  5. JS 判断鼠标滚轮的上下滚动

    JS 判断鼠标滚轮的上下滚动   <script type="text/javascript"> var scrollFunc = function (e) { e = ...

  6. JS判断鼠标移入元素的方向

    最终效果 这里的关键主要是判断鼠标是从哪个方向进入和离开的 $("li").on("mouseenter mouseleave",function(e) { v ...

  7. 关于js判断鼠标移入元素的方向--解释

    一开始我是这么想的,将待移入的元素分割四块,用mousemove获取第一次鼠标落入的区域来判断鼠标是从哪个方向进去的. 所以只要写个算法来判断鼠标的值落入该元素的区域就可以得出鼠标移入的方向,如下图: ...

  8. 关于js判断鼠标移入元素的方向——上下左右

    一开始我是这么想的,将待移入的元素分割四块,用mousemove获取第一次鼠标落入的区域来判断鼠标是从哪个方向进去的. 所以只要写个算法来判断鼠标的值落入该元素的区域就可以得出鼠标移入的方向,如下图: ...

  9. 2015.10.11(js判断鼠标进入容器的方向)

    判断鼠标进入容器的方向 1.前几天在万圣节专题项目中用到了鼠标坐标page事件,随着鼠标背景图片移动形成有层次感的效果,但page事件在IE低版本不支持,所以还要做兼容.在研究page事件同时无意中想 ...

随机推荐

  1. 《Mathematical Olympiad——组合数学》——染色问题

    恢复  继续关于<Mathematical Olympiad——组合数学>中问题的分析,这一篇文章将介绍有关染色的问题. 问题一: 将一些石头放入10行14列的矩形方格表内,允许在每个单元 ...

  2. 《JS原型》

    @(JavaScript原型) JavaScript中最晦涩难懂的恐怕就是原型了.故以此笔记本来记录原型的学习过程,日后忘了可来温习. 一切皆为对象 null--Object&Function ...

  3. OpenGL ES2.0基础入门

    1.OpenGL ES 1.x渲染管线(又称为渲染流水线) (1).基本处理: 基本处理主要是设定3D空间中物体的顶点坐标.顶点对应的颜色.顶点的纹理坐标等属性,并且指定绘制方式. 常见的绘制方式有: ...

  4. 赵雅智_ListView_BaseAdapter

    Android界面中有时候须要显示略微复杂的界面时,就须要我们自己定义一个adapter,而此adapter就要继承BaseAdapter,又一次当中的方法. Android中Adapter类事实上就 ...

  5. PHP CodeBase: 判断用户是否手机访问(转)

    随着移动设备的普及,网站也会迎来越来越多移动设备的访问.用适应PC的页面,很多时候对手机用户不友好,那么有些时候,我们需要判断用户是否用手机访问,如果是手机的话,就跳转到指定的手机友好页面.这里就介绍 ...

  6. QT的信号与槽机制介绍

      信号与槽作为QT的核心机制在QT编程中有着广泛的应用,本文介绍了信号与槽的一些基本概念.元对象工具以及在实际使用过程中应注意的一些问题. QT是一个跨平台的C++ GUI应用构架,它提供了丰富的窗 ...

  7. 根据IP地址获取IP的详细信息

    <?php header('Content-Type:text/html; charset=utf-8'); function ip_data() { $ip = GetIP(); $url = ...

  8. 将JSON数组显示前台Table中

    将JSON数组显示前台Table中 在最近的学习中遇到一个小问题,如何把JSON数组显示在前台的table中,经过一番借鉴和学习之后终于解决了这个问题.具体的代码如下: (前提:利用ajax获取过来的 ...

  9. Aircrack-ng 工具箱

    官网为:http://www.aircrack-ng.org/, 它就是一个与WiFi 相关的工具啦,可以进行一些注入,抓包.破解WiFI等.里面有很多不同的套件. 另外,http://blog.cs ...

  10. 转载:C#中的多态

    原文地址 http://www.cnblogs.com/jhxk/articles/1644018.html  感谢博主分享! 之前看到过类似的问题:如果面试时主考官要求你用一句话来描述多态,尽可能的 ...