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

jQuery圖片縮放插件smartZoom使用實(shí)例詳解

 更新時(shí)間:2017年08月25日 09:23:54   作者:joannau  
本文通過實(shí)例代碼給大家簡(jiǎn)單介紹了jQuery圖片縮放插件smartZoom使用以及遇到問題的解決方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

e-smart-zoom-jquery.js插件,下載地址及示例:https://github.com/e-smartdev/smartJQueryZoom

插件描述:通過將鼠標(biāo)懸停在圖片上,滾動(dòng)鼠標(biāo)滾輪即可實(shí)現(xiàn)圖片的放大或者縮小效果。

smartZoom使用

舉個(gè)栗子,上代碼:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>joannau</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    .imgCon {
      width: 800px;
      height: 500px;
      margin: 40px auto;
      border: 2px solid #000;
    }
    .imgDiv {
      width: 100%;
      height: 100%;
    }
    .imgCon img{
      width: 100%;
    }
  </style>
</head>
<body>
<div class="imgCon">
  <div class="imgDiv">
    <img src="./assets/zoomSmall.jpg" alt="">
  </div>
</div>
<script src="../src/jquery-1.11.0.min.js"></script>
<script src="../src/e-smart-zoom-jquery.js"></script>
<script>
  $(function () {
    $(".imgCon img").smartZoom()
  })
</script>
</body>
</html>

直接對(duì)img對(duì)象使用smartZoom方法即可。

查看效果:

縮放

完美,這就成功使用了。

但很多人會(huì)遇見使用smartZoom圖片位置偏移的問題,效果如下:

邊框不見,再看代碼會(huì)發(fā)現(xiàn):

原來是top和left作祟。此時(shí)解決問題的重點(diǎn)就是在img圖像外,嵌套一個(gè)div容器。如下:

<div class="imgDiv">
    <img src="./assets/zoomSmall.jpg" alt="">
  </div>

此時(shí),便能解決位置偏移問題。

其他API:

// 方法中可以通過設(shè)置top,left等參數(shù)來指定圖片初始參數(shù);
$(".imgCon img").smartZoom({
      'left': '50px'
    })
// 通過傳入‘destroy‘來取消縮放;
 $(".imgCon img").smartZoom('destroy')

總結(jié)

以上所述是小編給大家介紹的jQuery圖片縮放插件smartZoom使用實(shí)例詳解,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

最新評(píng)論