延迟弹出10秒,只弹出一次

编程入门 行业动态 更新时间:2024-10-27 15:29:36
本文介绍了延迟弹出10秒,只弹出一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我正在使用 fancybox 内联弹出窗口来提醒查看促销活动.我为此使用的代码是:

$(document).ready(function() {$("#various1").fancybox();});

如何修改它,让它在 20 秒后自动弹出?但是一旦关闭它就不会再弹出了.

解决方案

实际上,以前发布的解决方案都没有在现实生活中起作用,为什么?因为这行:

$("#various1").fancybox();

不会触发fancybox,它只是将fancybox 绑定到选择器#various1,但它仍然需要单击才能触发模态框/灯箱(不是弹出窗口).顺便说一句,Gearóid 的解决方案无论如何都有语法错误.唯一真正的价值是他们建议使用 jQuery cookie 插件(旧网站).

编辑:(2012 年 3 月 7 日)jQuery cookie 插件主页 已移动这里.

可行解决方案的步骤:

A) 在 jQuery 和 fancybox js 文件之后加载 jQuery cookie 插件(按照建议)

B) 然后使用这个脚本:

<script type="text/javascript">功能 openFancybox() {setTimeout(function() {$('#various1').trigger('click'); },20000);}$(文档).ready(函数() {varvisited = $.cookie('visited');如果(访问=='是'){返回假;} 别的 {openFancybox();}$.cookie('visited', 'yes', { expires: 7 });$('#various1').fancybox();});</脚本>

C) 你的 html 代码中仍然需要有某个地方(可能是隐藏的)

<a id="various1" href="path/target"></a>

或用于内联内容

<a id="various1" href="#target"></a><div style="display: none;"><div id="target">在fancybox中显示的消息</div></div>

此外,如果您使用内联内容和 fancybox v1.3.x,请检查现有错误和解决方法 这里

PS.fancybox 不是一个弹出窗口,而是一个模态/灯箱 jQuery 插件,从 UI 的角度来看,它是一个类似于 jGrowl 的非侵入式解决方案.

Hi I'm using the fancybox inline pop-up to to alert a view to a promotion. The code I'm using for this is:

$(document).ready(function() { $("#various1").fancybox(); });

How would I modify this so it automaticly popped up after, say, 20 seconds? But once it's been closed it schouldn't pop up again.

解决方案

Actually, none of the solutions posted previously work in real life, why? because the line:

$("#various1").fancybox();

doesn't trigger fancybox, it just binds fancybox to the selector #various1, but it still needs a click to trigger the modal/lightbox (not a popup). BTW, Gearóid's solution has syntax errors anyway. The only real value is that they suggest the use of the jQuery cookie plugin (old site).

EDIT: (March 07, 2012) The jQuery cookie plugin home page moved here.

Steps for a working solution:

A) Load the jQuery cookie plugin (as suggested) after jQuery and fancybox js files

B) Then use this script:

<script type="text/javascript"> function openFancybox() { setTimeout( function() {$('#various1').trigger('click'); },20000); } $(document).ready(function() { var visited = $.cookie('visited'); if (visited == 'yes') { return false; } else { openFancybox(); } $.cookie('visited', 'yes', { expires: 7 }); $('#various1').fancybox(); }); </script>

C) you still need to have somewhere in your html code (maybe hidden)

<a id="various1" href="path/target"></a>

or for inline content

<a id="various1" href="#target"></a> <div style="display: none;"> <div id="target">message to display in fancybox</div> </div>

Also, if you use inline content and fancybox v1.3.x, check for an existing bug and workaround here

PS. fancybox is not a popup but a modal/lightbox jQuery plugin, which is a non-intrusive solution like jGrowl from a UI point of view.

更多推荐

延迟弹出10秒,只弹出一次

本文发布于:2023-10-06 19:46:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467643.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!