繁体   English   中英

只显示一次弹出窗口(夸张弹出窗口)

[英]Show popup only once (magnific popup)

试图每次访问只显示一次此弹出窗口。 我觉得我错过了什么

<script src="http://code.jquery.com/jquery-1.7.min.js">
<link href="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet" type="text/css" media="all"/>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.js"></script>

<script>
$(document).ready(function() {
var check_cookie = $.cookie('bsw');
   if(check_cookie == null){
    $.cookie('bsw', 'yes', {expires: 1 });
  $('.image-link').magnificPopup({type:'image'});
});
</script>

<script>
(function($) {
    $(window).load(function () {
        // retrieved this line of code from http://dimsemenov.com/plugins/magnific-popup/documentation.html#api
        $.magnificPopup.open({
            items: {
                src: '/bsw-10-off.png'
            },
            type: 'image'

          // You may add options here, they're exactly the same as for $.fn.magnificPopup call
          // Note that some settings that rely on click event (like disableOn or midClick) will not work here
        }, 0);
    });
})(jQuery);
</script>

我没有关闭或打开正确的东西吗? 我觉得这个问题在文档就绪函数中,但我可能错了。 任何帮助,将不胜感激。 谢谢。

下面是没有cookie代码的代码

<link href="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet" type="text/css" media="all"/>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>

<script>
$(document).ready(function() {
  $('.image-link').magnificPopup({type:'image'});
});
</script>

<script>
(function($) {
    $(window).load(function () {
        // retrieved this line of code from http://dimsemenov.com/plugins/magnific-popup/documentation.html#api
        $.magnificPopup.open({
            items: {
                src: 'http://www.barbershopwindow.com/bfimages/bsw-10-off.png'
            },
            type: 'image'

          // You may add options here, they're exactly the same as for $.fn.magnificPopup call
          // Note that some settings that rely on click event (like disableOn or midClick) will not work here
        }, 0);
    });
})(jQuery);
</script>

代替:

//从http://dimsemenov.com/plugins/magnific-popup/documentation.html#api中检索到这行代码

初始化magnificPopup后,您可能只是触发click事件。

此外, $ .cookie('bsw')返回undefined,如果cookie不存在则不返回null。

工作jsfiddle

$(document).ready(function () {
    var check_cookie = $.cookie('bsw');
    if (check_cookie == undefined) {
        $.cookie('bsw', 'yes', {expires: 1});
        $('.image-link').magnificPopup({type: 'image'}).trigger('click');
    }
});
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.js"></script>



<a class="image-link" href="http://farm4.staticflickr.com/3721/9207329484_ba28755ec4_o.jpg">Open popup</a>

暂无
暂无

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

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