javascript - 如何在 jquery 中使用函数调用创建缩放效果

标签 javascript jquery

我有一段代码,当用户点击一个名为 zoomlink 时,会向用户显示一个 alert with a zoom effect..

当我点击一个按钮时,我希望同样发生 ...

当我尝试点击按钮时,它不起作用。

如何实现?如何修改代码?

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css'>
  <style>
    html,
    body {
      margin: 0;
      padding: 10px;
      -webkit-backface-visibility: hidden;
    }
    /* text-based popup styling */
    
    .white-popup {
      position: relative;
      background: #FFF;
      padding: 25px;
      width: auto;
      max-width: 400px;
      margin: 0 auto;
    }
    /* 

====== Zoom effect ======

*/
    
    .mfp-zoom-in {
      /* start state */
      /* animate in */
      /* animate out */
    }
    
    .mfp-zoom-in .mfp-with-anim {
      opacity: 0;
      transition: all 0.2s ease-in-out;
      transform: scale(0.8);
    }
    
    .mfp-zoom-in.mfp-bg {
      opacity: 0;
      transition: all 0.3s ease-out;
    }
    
    .mfp-zoom-in.mfp-ready .mfp-with-anim {
      opacity: 1;
      transform: scale(1);
    }
    
    .mfp-zoom-in.mfp-ready.mfp-bg {
      opacity: 0.8;
    }
    
    .mfp-zoom-in.mfp-removing .mfp-with-anim {
      transform: scale(0.8);
      opacity: 0;
    }
    
    .mfp-zoom-in.mfp-removing.mfp-bg {
      opacity: 0;
    }
  </style>
</head>

<body>
  <div class="links">
    <div class id="inline-popups">
      <a href="#test-popup" data-effect="mfp-zoom-in">Zoom</a>
      <button onClick="#test-popup" data-effect="mfp-zoom-in">test</button>

    </div>
  </div>

  <!-- Popup itself -->
  <div id="test-popup" class="white-popup mfp-with-anim mfp-hide">Game completed sucessfull</div>

  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js'></script>
  <script src="js/index.js"></script>
</body>

</html>

最佳答案

试试下面的

var theControl = $("#test-popup");
            $('#clickMe').magnificPopup({
                items: {
                    src: theControl,
                },
                type: 'inline',
                mainClass: 'mfp-with-zoom', // this class is for CSS animation below
                zoom: {
                    enabled: true, // By default it's false, so don't forget to enable it

                    duration: 300, // duration of the effect, in milliseconds
                    easing: 'ease-in-out', // CSS transition easing function

                    // The "opener" function should return the element from which popup will be zoomed in
                    // and to which popup will be scaled down
                    // By defailt it looks for an image tag:
                   
                }
            });
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css'>
    <style>
                html,
                body {
                    margin: 0;
                    padding: 10px;
                    -webkit-backface-visibility: hidden;
                }
                /* text-based popup styling */

                .white-popup {
                    position: relative;
                    background: #FFF;
                    padding: 25px;
                    width: auto;
                    max-width: 400px;
                    margin: 0 auto;
                }
                /*

        ====== Zoom effect ======

        */

                .mfp-zoom-in {
                    /* start state */
                    /* animate in */
                    /* animate out */
                }

                    .mfp-zoom-in .mfp-with-anim {
                        opacity: 0;
                        transition: all 0.2s ease-in-out;
                        transform: scale(0.8);
                    }

                    .mfp-zoom-in.mfp-bg {
                        opacity: 0;
                        transition: all 0.3s ease-out;
                    }

                    .mfp-zoom-in.mfp-ready .mfp-with-anim {
                        opacity: 1;
                        transform: scale(1);
                    }

                    .mfp-zoom-in.mfp-ready.mfp-bg {
                        opacity: 0.8;
                    }

                    .mfp-zoom-in.mfp-removing .mfp-with-anim {
                        transform: scale(0.8);
                        opacity: 0;
                    }

                    .mfp-zoom-in.mfp-removing.mfp-bg {
                        opacity: 0;
                    }
    </style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
 
<button id="clickMe" data-effect="mfp-zoom-in">test</button>
  <div id="test-popup" class="white-popup mfp-with-anim mfp-hide">Game completed sucessfully</div>
  

关于javascript - 如何在 jquery 中使用函数调用创建缩放效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54176527/

相关文章:

javascript - 数组中的JS对象如何返回自己的数组索引?

javascript - 网页上 div 中的“无尽滚动”

javascript - 如何检查 session 对象是否包含任何对象?

javascript - 将 HTML 绘制到 Canvas

javascript - 悬停/鼠标悬停时音频播放,可以在没有 jQuery 的情况下吗?

javascript - 基于所选链接的动态标题文本

javascript - 可以有多个 domready 事件吗?

javascript - 填充两个 DIV 元素之间的空白区域

javascript - 字符串包含使用替换后的替换值(Regex.last Match)

javascript - AngularJS Hello World 不起作用