简体   繁体   English

窗口加载调用magnificpopup

[英]window onload call magnificpopup

I have a script function its working fine in while i click a tag I need to call the function when site load or body load how to do this Please help me 我有一个脚本功能,可以在单击标签时正常工作,当我在站点加载或身体加载时需要调用该函数。

This is the code i used 这是我使用的代码

  <div class="html-code">
  <a href="#test-modal" class="popup-modal">Open modal</a>
            <div class="white-popup-block mfp-hide" id="test-modal">
  <span>hi</span>
   <p><a href="#" class="popup-modal-dismiss">Dismiss</a></p>
   </div>
 </div>
  <script type="text/javascript">
  $(function () {
    $('.popup-modal').magnificPopup({
      type: 'inline',
      preloader: true,
      focus: '#username',
      modal: true
    });
    $(document).on('click', '.popup-modal-dismiss', function (e) {
      e.preventDefault();
      $.magnificPopup.close();
    });
  });
  </script>

Have you tried to insert it into the 您是否尝试将其插入

$(document).ready(function() { ... } 

and call open() method? 并调用open()方法?

$(document).ready(function() {   
  $('.popup-modal').magnificPopup({
    type: 'inline',
    preloader: true,
    focus: '#username',
    modal: true
  }).open();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM