Chinaunix首页 | 论坛 | 博客
  • 博客访问: 927894
  • 博文数量: 210
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2070
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-19 21:54
文章分类

全部博文(210)

文章存档

2020年(2)

2019年(18)

2018年(27)

2017年(5)

2016年(53)

2015年(88)

2014年(17)

分类: jQuery

2016-09-08 21:49:06



点击(此处)折叠或打开

  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" />
  5.         <title></title>
  6.         <link rel="stylesheet" href="css/1.css" />
  7.         <script type='text/javascript' src="js/jquery-1.9.1.js"></script>
  8.         <script type="text/javascript" src="js/1.js"></script>
  9.     </head>
  10.     <body>
  11.         <div id="img">
  12.             <img src="img/4.jpg"/>
  13.         
  14.         </div>
  15.     
  16.             
  17.             <div id="mengban">
  18.                 
  19.                 <div id="lujin"></div>
  20.             </div>
  21.             
  22.     </body>
  23. </html>

点击(此处)折叠或打开

  1. window.onload = function(){
  2.     
  3.     
  4.     $(function(){
  5.         
  6.         $("#mengban").mouseover(function(e){
  7.          var e = event || window.event;
  8.             $("#lujin").show();
  9.             $("#mengban").mousemove(function(e){
  10.             
  11.              var x=e.pageX-50;
  12.              var y= e.pageY-50;
  13.                  console.log(x);
  14.                   console.log(y);
  15.                  
  16.                   if(x>700){
  17.                       x=700
  18.                   }
  19.                   if(x<0){
  20.                       x=0;
  21.                   }
  22.                   if(y>300){
  23.                       y=300;
  24.                   }
  25.                   if(y<0){
  26.                       y=0;
  27.                   }
  28.                $("#lujin").css('left', x+'px');
  29.                 $("#lujin").css('top', y+'px');
  30.                 $("#lujin").css("background-position",'-'+x+'px'+' '+'-'+y+'px');
  31.                

  32.             
  33.             
  34.             })
  35.             
  36.         })
  37.         $("#mengban").mouseout(function(){
  38.             $("#lujin").hide();
  39.             
  40.         })
  41.         
  42.         
  43.     })
  44.     
  45.     
  46.     
  47.     
  48. }


点击(此处)折叠或打开

  1. *{
  2.     margin: 0;
  3.     padding: 0;
  4. }
  5. #img img{
  6.     
  7.     width:800px;
  8.     height:400px;
  9. }

  10. #mengban{
  11.     width: 800px;
  12.     height: 400px;
  13.     background: black;
  14.     position: absolute;
  15.     top: 0px;
  16.     left: 0px;
  17.     opacity: 0.6;

  18. }
  19. #lujin{
  20.     width: 100px;
  21.     height: 100px;
  22.     background-image:url(../img/4.jpg);
  23.     background-repeat: no-repeat;
  24.     background-size: 800px 400px;
  25.     position: absolute;
  26.     display: none;
  27.     cursor: move;
  28.     
  29.     
  30.     top: 0;
  31.     left: 0;
  32.     
  33. }


阅读(1082) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~