2014-09-26 32 views
0

我試圖設置一個模式窗口,其中鼠標存在的窗口或點擊鏈接上的頁面。無法觸發ouibounce.js模式點擊

射擊退出是確定使用Ouibounce: http://carlsednaoui.github.io/ouibounce/

在Ouibounce API文檔建議我也應該能夠通過點擊來觸發模式。

我已經改變了鏈接在上面的例子中,給它#modal_button的ID,但我不能讓它火窗口:

// if you want to use the 'fire' or 'disable' fn, 
    // you need to save OuiBounce to an object 
    var _ouibounce = ouibounce(document.getElementById('ouibounce-modal'), { 
    aggressive: true, 
    timer: 0, 
    callback: function() { console.log('ouibounce fired!'); } 
    }); 


    $('#modal_button').on('click', function() { 
    $('#ouibounce-modal').fire(); 
    }); 



    $('body').on('click', function() { 
    $('#ouibounce-modal').hide(); 
    }); 


    $('#ouibounce-modal .modal-footer').on('click', function() { 
    $('#ouibounce-modal').hide(); 
    }); 

    $('#ouibounce-modal .modal').on('click', function(e) { 
    e.stopPropagation(); 
    }); 

我在這裏設立一個的jsfiddle它做同樣的事情。 http://jsfiddle.net/fr7k3s6f/

(出於某種原因對機體事件「隱藏」在的jsfiddle不工作)

回答

0

您需要使用您的對象_ouibounce調用在火()函數:

_ouibounce.fire(); 

而不是jQuery對象如果你在jQuery.ready()中定義它,它就需要是一個全局對象,所以沒有「var」之前,但我認爲這是當前版本中的一個錯誤(0.0.10 )。

我希望這會有所幫助。