2013-03-21 63 views
0

我正在從jQueryTools Overlay進行遷移,並且我無法真正掌握關於如何通過JavaScript單擊事件來打開Reveal的文檔。打開基礎揭示點擊和回調函數?

據說我有這樣的代碼:

<a href="#revealModal" class="revealTrigger">Click Me For A Modal</a> 
<div id="revealModal" class="reveal-modal"> 
    <p>Im a cool paragraph that lives inside of an even cooler modal. Wins</p> 
</div> 

通常情況下,我在jQueryTools疊加像代碼中的點擊事件:

$('.revealTrigger').click(function() { 
    $('#revealModal').reveal(); 
}); 

但是,這是行不通的。在Reveal中它對應的正確代碼是什麼?

回調事件呢?我可以寫這樣的事:

$('.revealTrigger').click(function() { 
    $('#revealModal').reveal({ 
     open: function(){ 
      // prepare some stuff before showing 
     }, 
     opened: function(){ 
      // execute stuff prepared by open function 
     }, 
    }); 
}); 

回答

4

揭密模式可以通過兩種方式打開,按屬性:

<a href="#" data-reveal-id="myModal">Click Me For A Modal</a> 
<div id="myModal" class="reveal-modal"> 
     <h2>Awesome. I have it.</h2> 
     <p class="lead">Your couch. It is mine.</p> 
     <p>Im a cool paragraph that lives inside of an even cooler modal. Wins</p> 
     <a class="close-reveal-modal">&#215;</a> 
    </div> 

或由JavaScript:

<a class="large button" onclick="javascript:showModal();" href="#">Show Modal</a> 

<script> 
    $('#myModal').foundation('reveal', { 
      opened: function() { 
       alert('The couch was stolen!'); 
      }, 
      closed: function() { 
       alert("Now it's yours again"); 
      } 
    }); 
    $(document).foundation(); 
    function showModal() { 
     $('#myModal').foundation('reveal', 'open');   
    } 
</script> 
+0

如何回調事件? – Ramil 2013-03-21 11:23:38

+0

查看我更新的答案,有人告訴我爲了使配置工作,它**重要**,您在**基礎初始化之前先執行設置**('$(document).foundation();') – 2013-03-21 12:07:09

+0

它的工作,但我決定使用另一個插件。看來它不能做我想要的。 – Ramil 2013-03-23 09:42:25

0

您也可以綁定開放,關閉和關閉事件。

#CoffeeScript 
$("div[class$='-modal']").on "opened", -> 
    console.log "howdy" 
0

請使用下面的代碼

$('#modal_id').bind('closed', function() { 
    console.log("myModal closed!"); 
    });