Foundation 6 显示在页面加载时打开且 cookie 不起作用
Foundation 6 reveal open on page load with cookies not working
我正在尝试创建一个模态显示,它在使用 zurb foundation 6 加载页面时打开。我还希望浏览器存储一个 cookie,这样如果用户关闭显示,它就不会再打扰他们 7天。
我正在为找到的 cookie 使用 jquery 插件 here
这是我的 html:
<div class="reveal" id="exampleModal1" data-reveal>
<h1>Awesome. I Have It.</h1>
<p class="lead">Your couch. It is mine.</p>
<p>I'm a cool paragraph that lives inside of an even cooler modal. Wins!</p>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
如您所见,我没有数据打开元素,因为我希望模式在页面加载后打开。
这是我的 jquery:
jQuery(document).ready(function($) {
if ($.cookie('modal_shown') === null) {
$.cookie('modal_shown', 'yes', { expires: 7, path: '/' });
$("#exampleModal1").foundation('reveal', 'open');
}
});
jquery 处于无冲突模式。
但这似乎不起作用。在 chrome 中,我的开发者控制台没有收到任何错误。我真的很感激你的帮助。
我已经发布了解决方案,以防其他人需要它。
原来在foundation 6中,你不需要同时使用reveal和open方法,open就可以了。
jQuery(document).ready(function($) {
if($.cookie('showed_modal') != "true") {
$("#exampleModal1").foundation("open");
$.cookie('showed_modal', 'true', { expires: 7, path: '/'});
}
});
我正在尝试创建一个模态显示,它在使用 zurb foundation 6 加载页面时打开。我还希望浏览器存储一个 cookie,这样如果用户关闭显示,它就不会再打扰他们 7天。
我正在为找到的 cookie 使用 jquery 插件 here
这是我的 html:
<div class="reveal" id="exampleModal1" data-reveal>
<h1>Awesome. I Have It.</h1>
<p class="lead">Your couch. It is mine.</p>
<p>I'm a cool paragraph that lives inside of an even cooler modal. Wins!</p>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
如您所见,我没有数据打开元素,因为我希望模式在页面加载后打开。
这是我的 jquery:
jQuery(document).ready(function($) {
if ($.cookie('modal_shown') === null) {
$.cookie('modal_shown', 'yes', { expires: 7, path: '/' });
$("#exampleModal1").foundation('reveal', 'open');
}
});
jquery 处于无冲突模式。
但这似乎不起作用。在 chrome 中,我的开发者控制台没有收到任何错误。我真的很感激你的帮助。
我已经发布了解决方案,以防其他人需要它。
原来在foundation 6中,你不需要同时使用reveal和open方法,open就可以了。
jQuery(document).ready(function($) {
if($.cookie('showed_modal') != "true") {
$("#exampleModal1").foundation("open");
$.cookie('showed_modal', 'true', { expires: 7, path: '/'});
}
});