<script type="text/javascript"> $(document).ready(function() { var scale = 1; // scale of the image var xLast = 0; // last x location on the screen var yLast = 0; // last y location on the screen var xImage = 0; // last x location on the image var yImage = 0; // last y location on the image // 如果鼠标移动 $("#mosaicContainer").mousewheel(function(e, delta) { // 当前屏幕上的位置 var xScreen = e.pageX - $(this).offset().left; var yScreen = e.pageY - $(this).offset().top; // find current location on the image at the current scale xImage = xImage + ((xScreen - xLast) / scale); yImage = yImage + ((yScreen - yLast) / scale); // determine the new scale if (delta > 0) { scale *= 2; } else { scale /= 2; } scale = scale < 1 ? 1 : (scale > 64 ? 64 : scale); // determine the location on the screen at the new scale var xNew = (xScreen - xImage) / scale; var yNew = (yScreen - yImage) / scale; // 保存当前位置 xLast = xScreen; yLast = yScreen; // redraw $(this).find('div').css('-moz-transform', 'scale(' + scale + ')' + 'translate(' + xNew + 'px, ' + yNew + 'px' + ')') .css('-moz-transform-origin', xImage + 'px ' + yImage + 'px') return false; }); });
转载于:https://www.cnblogs.com/muzijia/archive/2012/11/13/2767401.html
原文链接:https://blog.csdn.net/weixin_30342827/article/details/95438150
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
评论前必须登录!
立即登录