【问题标题】:Foundation 6 reveal open on page load with cookies not workingFoundation 6 在页面加载时显示打开,但 cookie 不起作用
【发布时间】:2016-03-03 16:56:18
【问题描述】:

我正在尝试创建一个模式显示,该显示在使用 zurb Foundation 6 的页面加载时打开。我还希望浏览器存储一个 cookie,以便如果用户关闭显示,它不会再打扰他们 7 天。

我正在使用一个 jquery 插件来找到 here 的 cookie

这是我的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">&times;</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 中通过我的开发者控制台没有收到任何错误。我非常感谢您的帮助。

【问题讨论】:

    标签: javascript jquery cookies zurb-foundation


    【解决方案1】:

    我已经发布了解决方案,以防其他人需要它。

    原来在foundation 6中,你不需要同时使用reveal和open方法,直接open即可。

    jQuery(document).ready(function($) {
      if($.cookie('showed_modal') != "true") {
        $("#exampleModal1").foundation("open");
        $.cookie('showed_modal', 'true', { expires: 7, path: '/'}); 
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多