如何将图像放大 120%、150% 和 180%?

Po *_*ong 2 javascript jquery magnific-popup

感谢您阅读我的帖子。

我正在使用放大弹出窗口 - 缩放功能。我想知道如何设置缩放百分比,以及如何通过单击弹出图像来进行 3 种不同程度的放大。

只是想澄清我的障碍:例如,我想单击放大的弹出图像,然后放大到120%,第二次单击,放大到150%,第三次单击,放大到180%,然后第四次单击 ,将缩小回 100%。

有谁知道这是怎么做到的吗?如果是的话,对我有很大帮助。非常感谢!

原始代码(有效):


$('#img').magnificPopup({ 
          delegate: 'a',
          type: 'image',
          callbacks: {
              open: function() {
                $(".mfp-figure figure").css("cursor", "zoom-in");
                $(".mfp-figure figure").zoom({ 
                    on: "click",
                    onZoomIn: function () {
                        $(this).css("cursor", "zoom-out");
                    },
                    onZoomOut: function () {
                        $(this).css("cursor", "zoom-in");
                    }
                });
              },
              close: function() {
                // Will fire when popup is closed
              }
              // e.t.c.
            }
        });
Run Code Online (Sandbox Code Playgroud)

我的代码(不起作用):


$('#img').magnificPopup({ 
          delegate: 'a',
          type: 'image',
          callbacks: {
              open: function() {
                $(".mfp-figure figure").css("cursor", "zoom-in");
                $(".mfp-figure figure").zoom({ 
                    on: "click",
                    onZoomIn: function () {
                        $(this).zoom({
                            on: "click",
                            onZoomIn: function(){
                            },
                            onZoomOut: function(){
                            }
                        });
                        $(this).css("cursor", "zoom-out");
                    },
                    onZoomOut: function () {
                        $(this).css("cursor", "zoom-in");
                    }
                });
              },
              close: function() {
                // Will fire when popup is closed
              }
              // e.t.c.
            }
        });
Run Code Online (Sandbox Code Playgroud)

Po *_*ong 6

最后我放弃了Magnifier Popup - 缩放功能,而用css - 缩放功能代替。

解决方案:


`var zoom_percent = "100";
        function zoom(zoom_percent){
            $(".mfp-figure figure").click(function(){
                switch(zoom_percent){
                    case "100":
                        zoom_percent = "120";
                        break;
                    case "120":
                        zoom_percent = "150";
                        break;
                    case "150":
                        zoom_percent = "200";
                        $(".mfp-figure figure").css("cursor", "zoom-out");
                        break;
                    case "200":
                        zoom_percent = "100";
                        $(".mfp-figure figure").css("cursor", "zoom-in");
                        break;
                }
                $(this).css("zoom", zoom_percent+"%");
            });
        }

        $('#img').magnificPopup({ 
          delegate: 'a',
          type: 'image',
          callbacks: {
              open: function() {
                  $(".mfp-figure figure").css("cursor", "zoom-in");
                  zoom(zoom_percent);
              },
              close: function() {
                // Will fire when popup is closed
              }
              // e.t.c.
            }

        });`
Run Code Online (Sandbox Code Playgroud)

希望这对也在寻找它的人有所帮助。