发布于 2017-05-27 05:26:28 | 134 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Javascript教程,程序狗速度看过来!

JavaScript客户端脚本语言

Javascript 是一种由Netscape的LiveScript发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如Perl,遗留的速度问题,为客户提供更流畅的浏览效果。


这篇文章主要为大家详细介绍了js实现放大镜特效,简单实用的代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了js放大镜特效的实现代码,供大家参考,具体内容如下


<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8" />
 <title>Document</title>
 <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
 <style type="text/css">
  *{
   margin: 0;
   padding: 0;
  }
  .imgBox{
   width: 1000px;
   margin: auto;
   text-align: center;
  }
  .small,.large{
   font-size: 0;
   outline: 1px solid burlywood;
   margin: auto;
  }
  .small{
   margin: 20px auto;
  }
  .large{
   /*display: none;*/
  }
  .small,.small img,.large{
   width: 300px;
   height: 200px;
   overflow: hidden;
  }
  .large img{
   width: 900px;
   height: 600px;
  }
  .small,.large{
   position: relative;
  }
  .mark{
   opacity: 0.5;
   background-color: #DEB887;
   z-index: 55;
   width: 100px;
   height: 66.666666666px;
   display: none;
  }
  .mark,.large img{
   position: absolute;
   left: 0;
   top: 0;
  }
 </style>
</head>
<body>
 <div class="imgBox">
  <div class="small">
   <img src="img/img_14.jpg"/>
   <div class="mark"></div>
  </div>
  <div class="large">
   <img src="img/img_14.jpg"/>
  </div>
 </div>
 
 <script type="text/javascript">
  $(function(){
   var $small = $(".small"),
    $mark = $(".mark"),
    $large = $(".large");
   $small.on("mousemove",function(e){
// 在鼠标移到小图片中显示出mark
    $mark.css("display","block");
//    $large.css("display","block");
// 获取mark的一半宽度高度
    var hw = $mark.width()/2,
     hh = $mark.height()/2;
// 获取鼠标在当前图片中的位置
    var lf = e.pageX-$small.offset().left-hw,
     tt = e.pageY-$small.offset().top-hh;
// 获取mark的想x,y轴偏移率
    var ix = lf/$small.width(),
     iy = tt/$small.height();
// 获取边缘线
    var lb = 1-hw/$small.width()*2,
     tb = 1-hh/$small.height()*2;
// 计算和边缘的关系
    var ix = ix<lb?ix>0?ix:0:lb,
     iy = iy<tb?iy>0?iy:0:tb;
// 进行大图和小图百分比计算
    $mark.css("left",ix*100+"%").css("top",iy*100+"%");
    $large.children().css("left",-ix*300+"%").css("top",-iy*300+"%");
   }).on("mouseout",function(){
// 鼠标移出后mark隐藏
    $mark.css("display","none");
//    $large.css("display","none");
   })
  })
 </script>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持phperz。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务