日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图片的缩放与拖拽

發布時間:2024/9/27 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图片的缩放与拖拽 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


這個圖片的縮放的流暢度還是很好的,需要引入touch.js,好像是百度團隊那邊寫的

<script src="./js/touch.min.js" type="text/javascript"></script> $(function() { //放大縮小var scaleVal = 1;var initialScale = scaleVal || 1; var currentScale; touch.on('.swiper-mast img', 'pinch', function (ev) { currentScale = ev.scale - 1; currentScale = initialScale + currentScale; scaleVal = currentScale;if(scaleVal < 0.5){scaleVal = 0.5;} var transformStyle = 'scale(' + scaleVal + ')'; $(this).css("transform", transformStyle).css("-webkit-transform", transformStyle); }); touch.on('.swiper-mast img', 'pinchend', function (ev) { initialScale = currentScale; scaleVal = currentScale; }); }); 拖拽目標元素$(function() {touch.on('.swiper-mast img', 'touchstart', function(ev) {ev.preventDefault();});var dx, dy;touch.on('.swiper-mast img', 'drag', function(ev) {dx = dx || 0;dy = dy || 0;var offx = dx + ev.x;var offy = dy + ev.y;if(offx < 0){offx = 0;}if(offy < 0){offy = 0;}$(this).css("left", offx+'px').css("top", offy+'px');// alert(offx);// alert(offy);});touch.on('.swiper-mast img', 'dragend', function(ev) {dx += ev.x;dy += ev.y;});});

html代碼:

<div class="swiper-mast"><div class="swiper-container"><div class="swiper-wrapper"><div class="swiper-slide"><img src="./img/libai.jpg" alt=""></div><div class="swiper-slide"><img src="./img/libai.jpg" alt=""></div><div class="swiper-slide"><img src="./img/libai.jpg" alt=""></div><div class="swiper-slide"><img src="./img/libai.jpg" alt=""></div><div class="swiper-slide"><img src="./img/libai.jpg" alt=""></div></div><div class="swiper-pagination"></div></div></div>

網址:(https://ptestjava.liby.com.cn/wechat/goodsdetail.html)

總結

以上是生活随笔為你收集整理的图片的缩放与拖拽的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。