博主信息
博文 9
粉丝 0
评论 2
访问量 8565
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
js实现鼠标从不同方向移入效果
Fergus的博客
原创
961人浏览过

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>鼠标从不同方向移入-jq22.com</title>
<script src="../jquery-3.2.1.min.js"></script>
<style>
html,body {
  height:100%;
  overflow:hidden;
}
#wrap {
  width:1400px;
  height:100%;
  margin:0px auto;
}
#wrap ul li {
  position:relative;
  float:left;
  width:230px;
  height:360px;
  list-style:none;
  margin-right:12px;
  overflow:hidden;
}
#wrap ul li img {
  display:block;
}
#wrap ul li .cover {
  position:absolute;
  width:230px;
  height:360px;
  top:0px;
  left:230px;
  background:url(./images/fergus_bg.png);
}
#wrap ul li .cover p {
  font-size:14px;
  color:#fff;
  text-align:center;
}
#wrap ul li .cover p.p1 {
  padding-top:160px;
}
</style>
</head>
<body>
<div id="wrap">
 <ul>
   <li> <img width="230" height="360" src="images/fergus.png"/>
     <div class='cover'>
       <p class='p1'> 春夏新品 上新无限 </p>
       <p> 点击进入 </p>
     </div>
   </li>
   <li> <img width="230" height="360" src="images/fergus.png"/>
     <div class='cover'>
       <p class='p1'> 夏装新品发布 8折起 </p>
       <p> 点击进入 </p>
     </div>
   </li>
   <li> <img width="230" height="360" src="images/fergus.png"/>
     <div class='cover'>
       <p class='p1'> 春装特惠 买二送一 </p>
       <p> 点击进入 </p>
     </div>
   </li>
   <li> <img width="230" height="360" src="images/fergus.png"/>
     <div class='cover'>
       <p class='p1'> 春夏新品 低至158 </p>
       <p> 点击进入 </p>
     </div>
   </li>
 
 </ul>
</div><script>
(function() {

   var $li = $('#wrap ul li');

   $li.hover(function(e) {

       move.call(this, e, true);

   },
   function(e) {
       move.call(this, e, false);
   });

   function move(e, bool) {
       var top = $(this).offset().top;
       var bottom = top + $(this).height();
       var left = $(this).offset().left;
       var right = left + $(this).width();

       var x = e.pageX,
       y = e.pageY;

       var sT = Math.abs(y - top),
       sB = Math.abs(y - bottom),
       sL = Math.abs(x - left),
       sR = Math.abs(x - right);

       var a = Math.min(sT, sB, sL, sR);

       switch (a) {
       case sT:
           if (bool) {
               $(this).find('.cover').css({
                   left:
                   0,
                   top: '-360px'
               }).stop().animate({
                   top: 0
               },
               400);
           } else {
               $(this).find('.cover').stop().animate({
                   top: '-360px'
               },
               400);
           }

           break;

       case sB:
           if (bool) {
               $(this).find('.cover').css({
                   left:
                   0,
                   top: '360px'
               }).stop().animate({
                   top: 0
               },
               400);
           } else {
               $(this).find('.cover').stop().animate({
                   top: '360px'
               },
               400);
           }
           break;

       case sL:

           if (bool) {
               $(this).find('.cover').css({
                   top:
                   0,
                   left: '-230px'
               }).stop().animate({
                   left: 0
               },
               400);
           } else {
               $(this).find('.cover').stop().animate({
                   left: '-230px'
               },
               400);
           }

           break;

       case sR:
           if (bool) {
               $(this).find('.cover').css({
                   top:
                   0,
                   left: '230px'
               }).stop().animate({
                   left: 0
               },
               400);
           } else {
               $(this).find('.cover').stop().animate({
                   left: '230px'
               },
               400);
           }
           break;
       }

       //console.log( '距离顶部:'+sT+'   距离底部:'+sB+'   距离左边:'+sL+'   距离右边:'+sR )
   };

})();</script>
</body>
</html>

fergus.png

本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学