elevateZoom的使用(适用于只有一张图)

html:

用<script src='..'>引入elevatezoom的js

在要使用的图片<img>里面加上属性:data-zoom-image=‘任意图片路径’(该图片不重要)

 

js:

自己定义一个函数:

function elevatezoom_show(url, box) {
var big = $(box).data('elevateZoom'); //box放img的id或者类名
big.swaptheimage(url, url);

}

 

在id处调用放大镜:(可以在option里面设置放大镜配置,也可以去掉option,此时为默认配置)

var option = { zoomWindowOffety: 190, zoomWindowOffetx: -340, zoomWindowWidth: 700, zoomWindowHeight: 800 };

$('#我是图片id').elevateZoom(option);

 

直接在引入图片的地方调用函数:

elevatezoom_show(url, box) // url放图片地址,box放img的id

 

放大镜就搞定了!!

另附:

elevateZoom的配置表:

 

参数描述默认值
responsiveSet to true to activate responsivenes. If you have a theme which changes size, or tablets which change orientation this is needed to be on. Possible Values:false
scrollZoomSet to true to activate zoom on mouse scroll. Possible Values:false
imageCrossfadeSet to true to activate simultaneous crossfade of images on gallery change. Possible Values:false
loadingIconSet to the url of the spinner icon to activatfalse
easingSet to true to activate easing.false
easingTypedefault easing type is easeOutExpo, (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b Extend jquery with other easing types before initiating the plugin and pass the easing type as a string value.zoomdefault

easingDuration

lensSizeused when zoomType set to lens, when zoom type is set to window, then the lens size is auto calculated200
zoomWindowWidthWidth of the zoomWindow (Note: zoomType must be400
zoomWindowHeightHeight of the zoomWindow (Note: zoomType must be400
zoomWindowOffetxx-axis offset of the zoom window0
zoomWindowOffetyy-axis offset of the zoom window0
zoomWindowPositionOnce positioned, use zoomWindowOffsetx and zoomWindowOffsety to adjust Possible values: 1-161
zoomTintFadeInSet as a number e.g 200 for speed of Tint fadeInfalse
zoomTintFadeOutSet as a number e.g 200 for speed of Tint fadeOutfalse
borderSizeBorder Size of the ZoomBox - Must be set here as border taken into account for plugin calculations4
galleryThis assigns a set of gallery links to the zoom imagenull
tintenable a tint overlay, other options: truefalse
tintColourcolour of the tint, can be #hex, word (red, blue), or rgb(x, x, x)#333
tintOpacity0.4opacity of the tint
zoomLensset to false to hide the Lenstrue

 

该表出处:http://www.sucaihuo.com/js/127.html

 

 

注意:一般放大镜都是一大一小两张图 ,该方法适用只有一张大图的时候。如有两张图,将函数里面的big.swaptheimage(url, url);放入不同图片地址,修改函数重新调用

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是两种jQuery片放大镜的代码: 1. 使用HTML和CSS实现片放大镜效果: ```html <div id="box"> <img src="./哈哈.jpg" alt=""> // 正常显示的片 <div id="xiao"></div> </div> <div id="box2"> <img src="./哈哈.jpg" alt="" id="big"> // 要放大的片 </div> <style> #box { position: relative; width: 400px; height: 400px; } #xiao { position: absolute; width: 100px; height: 100px; background-color: rgba(0, 0, 0, 0.5); display: none; } #box2 { position: relative; width: 400px; height: 400px; overflow: hidden; } #big { position: absolute; width: 800px; height: 800px; display: none; } </style> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $("#box").mousemove(function(e) { var x = e.pageX - $(this).offset().left; var y = e.pageY - $(this).offset().top; var xPercent = x / $(this).width(); var yPercent = y / $(this).height(); var bigImgWidth = $("#big").width(); var bigImgHeight = $("#big").height(); var moveX = -(bigImgWidth - $(this).width()) * xPercent; var moveY = -(bigImgHeight - $(this).height()) * yPercent; $("#big").css({ "left": moveX, "top": moveY }); $("#xiao").css({ "left": x - 50, "top": y - 50 }); }); $("#box").hover(function() { $("#xiao").show(); $("#big").show(); }, function() { $("#xiao").hide(); $("#big").hide(); }); }); </script> ``` 2. 使用jQuery插件实现片放大镜效果: ```html <div id="smallBox"> <img src="/img/1.png" alt=""> <div id="zoom"></div> </div> <div id="bigBox"> <img src="/img/1.png" alt=""> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="jquery.elevatezoom.js"></script> <script> $(document).ready(function() { $("#smallBox").elevateZoom({ zoomType: "inner", cursor: "crosshair", zoomWindowFadeIn: 500, zoomWindowFadeOut: 500 }); }); </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值