Igor150195

Лупа

Apr 23rd, 2020
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
  2. if (!isMobile && jQuery().zoom) {
  3.     $('.gr-image-zoom').zoom({
  4.         magnify: 1,
  5.         duration: 10,
  6.         onZoomIn: function(){
  7.             $(this).parent().addClass('hide_small_pic');
  8.         },
  9.         onZoomOut: function(){
  10.             $(this).parent().removeClass('hide_small_pic');
  11.         },
  12.         callback: function(){
  13.             var $zoomImg = $(this);
  14.             var zoomImgHeight = Math.floor($zoomImg.height());
  15.             var zoomImgWidth = Math.floor($zoomImg.width());
  16.             var floatHeight = Math.floor(20 * zoomImgHeight / 100);
  17.             var floatWidth = Math.floor(20 * zoomImgWidth / 100);
  18.             var prevWidth = Math.floor($(this).prev().outerWidth());
  19.             var prevHeight = Math.floor($(this).prev().outerHeight());
  20.  
  21.             var zoomFloatHeight = zoomImgHeight + floatHeight;
  22.             var zoomFloatWidth = zoomImgWidth + floatWidth;
  23.             var finalHeight = prevHeight+floatHeight;
  24.             var finalWidth = prevWidth+floatWidth;
  25.  
  26.             if (zoomFloatHeight<=prevHeight-floatHeight || zoomFloatWidth<=prevWidth-floatWidth) {
  27.                 $(this).parent().addClass('hide_big_pic');
  28.             };
  29.  
  30.             if (zoomImgHeight<=prevHeight || zoomImgWidth <=prevWidth) {
  31.                 $zoomImg.css({
  32.                     'width': finalWidth,
  33.                     'height': finalHeight
  34.                 });
  35.             }
  36.         }
  37.     });
  38. };
Add Comment
Please, Sign In to add comment