如何用哈希(#)打开Foundation Reveal Modal

时间:2013-10-31 14:40:31

标签: jquery zurb-foundation reveal.js

如果某种可能的话,有人能指出我正确的方向。

我想要发送给用户的电子邮件,其中包含指向特定页面的链接。我在该页面上有模态,我希望根据网址打开具有特定模态的页面。 例如:

domain.com/story/#story1

打开包含身份#story1

的OPEN揭示模式的页面

如果有人可以提供帮助,我真的很感激。

我设法通过

导航到页面时打开模态窗口
("#Modal8").foundation('reveal', 'open');

有人建议我使用

<script>
    var hash = window.location.hash;

    if (hash === "#story8") {
        $('#Modal8').reveal({ 
            animation: 'fadeAndPop',                 //fade, fadeAndPop, none
            animationspeed: 300,                    //how fast animtions are
            closeonbackgroundclick: true,           //if you click background will modal close?
            dismissmodalclass: 'close-reveal-modal' //element that will close an open modal
        }); //You can use same modal or different modal to show success message
    } 
</script>

我尝试过没有成功。

2 个答案:

答案 0 :(得分:1)

我正在为我的项目使用Expressionengine,所以我提出了一个简单的解决方案。也许它会帮助别人。我在页面上有8个模态,我有8个条件。我猜你可以在通道中使用条件。 :)

{if last_segment == 'Modal8'}  //Modal8 can be changed to any url: latestnews or smth.
$("#Modal8").foundation('reveal', 'open'); 
</script>
{/if}

答案 1 :(得分:0)

if (window.location.hash){
    $(document).ready(function () {
      let $blockHash = $(window.location.hash);
      //console.log($blockHash);
      if (($blockHash.length > 0) && ($blockHash.hasClass('reveal'))){
        $blockHash.foundation('open');//foundation 6
      }
    });
}