欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery實現(xiàn)的放大鏡效果示例

 更新時間:2020年02月24日 11:49:10   作者:巴啦啦小能量  
這篇文章主要介紹了jquery實現(xiàn)的放大鏡效果,結(jié)合實例形式分析了jQuery放大鏡插件shoplistxq.js的定義與使用相關操作技巧,需要的朋友可以參考下

本文實例講述了jquery實現(xiàn)的放大鏡效果。分享給大家供大家參考,具體如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>商品詳情</title>
  <link rel="stylesheet" href="../css/shoplistxq.css" rel="external nofollow" >
</head>
<body>
  <div class="main box">
    <div class="img">
      <img src="../img/shoplist/TB1lO6XJpXXXXc_XFXXLhc5_XXX_054423.jpg" alt="">
      <div class="bri"></div>
      <div class="big"></div>
    </div>
    <div class="content">
      <h3>2件衛(wèi)衣男士長袖t恤加厚打底衫加絨秋衣保,<br>
        暖上衣男裝冬季衣服潮
      買一送一!2件僅需89!加絨不加價!</h3>
      <div>價格¥ 168.00</div>
      <div>尺碼</div>
      <div>顏色</div>
      <div>數(shù)量</div>
      <div>加入購物車</div>
    </div>
  </div>
</body>
</html>
<script src="../js/jquery-1.11.3.js"></script>
<script src="../js/shoplistxq.js"></script>

shoplistxq.css:

*{
 margin:0;
 padding:0;
 font-family: "微軟雅黑";
}
ul li{
 list-style: none;
}
a{
 text-decoration: none;
 color: #666;
}
/*主體寬度*/
.main {
 margin:0 auto;
 width: 1210px;
}
.box{
  margin-top: 50px;
}
.box::after{
  content: ".";
  height:0;
  overflow: hidden;
  visibility: hidden;
  clear: both;
}
.img{
  width: 400px;
  height: 400px;
  border: 1px solid #666666;
  position: relative;
  float: left;
}
.img img{
  width: 100%;
  height: 100%;
}
.bri{
  position: absolute;
  width: 100px;
  height: 100px;
  left:0;
  top:0;
  background: rgb(233, 118, 118);
  opacity: .5;
  cursor: crosshair;
}
.big{
  width:100%;
  height: 100%;
  position: absolute;
  background: url("../img/shoplist/TB1lO6XJpXXXXc_XFXXLhc5_XXX_054423.jpg");
  left:401px;
  top:0;
  background-size: 100%;
  display:none;
}
.content{
  float: right;
}

shoplistxq.js:

$(function() {
  $(".img").mousemove(function (e) {
    $(".bri").css({
      "left": e.pageX - $(this).offset().left - $(".bri").width() / 2,
      "top": e.pageY - $(this).offset().top - $(".bri").height() / 2
    })
    if (parseFloat($(".bri").css("left")) < 0){
      $(".bri").css("left","0");
      // console.log("kk");
    } else if (parseFloat($(".bri").css("left")) >= parseFloat($(this).width() - $(".bri").width())){
      // alert("kk");
      $(".bri").css("left",$(this).width() - $(".bri").width());
    }
    if (parseFloat($(".bri").css("top")) < 0) {
      $(".bri").css("top", "0");
    } else if (parseFloat($(".bri").css("top")) >= parseFloat($(this).height() - $(".bri").height())) {
      // alert("kk");
      $(".bri").css("top", $(this).height() - $(".bri").height());
    }
    console.log($(".img").css("background"))
    // 放大倍數(shù)
    let num = 4;
    let left = -num * parseFloat($(".bri").css("left"));
    let top = -num * parseFloat($(".bri").css("top"));
    // console.log($(".bri").css("left"))
    $(".big").css({
      "background-size": num*100+"%",
      "background-position":left+"px " +top+"px",
      "display":"block"
      // "background": $(".img").css("background")
    });
  })
})
$(".img").mouseout(function (e) {
  $(".big").css({
    "display": "none"
    // "background": $(".img").css("background")
  });
})

更多關于jQuery相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設計有所幫助。

相關文章

最新評論