js案例之鼠标跟随jquery版(实例讲解)

网络编程 2021-07-04 18:32www.168986.cn编程入门
狼蚁网站SEO优化长沙网络推广就为大家带来一篇js案例之鼠标跟随jquery版(实例讲解)。长沙网络推广觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随长沙网络推广过来看看吧

废话不多说,直接上代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    body,div{
      margin:0;
      padding:0;
    }
    img{
      display:block;
      border:none;
    }
    .box{
      position:relative;
      width:450px;
      margin:20px auto;
    }
    .box img{
      float:left;
      margin-left:10px;
      width:100px;
      height:75px;
      border:1px solid #008000;
    }
    #mark{
      display:none;
      position:absolute;
      :0;
      left:0;
      z-index:10;
      width:400px;
      height:300px;
      border:1px solid #0077b0;
    }
    #mark img{
      float:inherit;
      margin-left:0;
      border:none;
      width:100%;
      height:100%;
    }
  </style>
</head>
<body>
  <div class='box' id='box'>
    <img src="img/apple_1.jpg" alt="" bigImg='img/apple_1_bigger.jpg'>
    <img src="img/apple_2.jpg" alt="" bigImg='img/apple_2_bigger.jpg'>
    <img src="img/apple_3.jpg" alt="" bigImg='img/apple_3_bigger.jpg'>
    <img src="img/apple_4.jpg" alt="" bigImg='img/apple_4_bigger.jpg'>
    <div id='mark'>
      <img src="img/apple_1_bigger.jpg" alt="">
    </div>
  </div>

  <script src='js/jquery-1.11.3.min.js'></script>
  <script>
    $(function(){
      var $box = $("#box"),$mark = $("#mark");
      var $boxOffset = $box.offset();//获取当前元素的距离body的偏移
      $box.children("img").bind("mouseover",function(e){
        var e = e || window.event;
        e.target = e.target || e.srcElement;
        var left = e.clientX - $boxOffset.left+10;
        var  = e.clientY - $boxOffset.+10;
        $mark.s().show(500).css({left:left,:}).find("img").attr("src",e.target.getAttribute("bigImg"));

      }).bind("mousemove",function(e){
        var e = e || window.event;
        e.target = e.target || e.srcElement;
        var left = e.clientX - $boxOffset.left+10;
        var  = e.clientY - $boxOffset.+10;
        $mark.css({left:left,:}).find("img").attr("src",e.target.getAttribute("bigImg"));

      }).bind("mouseout",function(e){
        $mark.s().hide(500);

      })


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

以上这篇js案例之鼠标跟随jquery版(实例讲解)就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by