I am trying to run some javascript ONLY on the condition that the reveal modal is active. The problem is that the methods I have tried have been True whether the modal is active or not. Below is an example of what I am trying to accomplish. I have tried :is visible method, also :active. I am using zurb reveal modal.
The html:
<div id="myModal" class="reveal-modal">
<ul>
<li>some list item</li>
<li>some list item</li>
</ul>
</div> <!--/myModal-->
The JS:
<script>
if ($('#myModal:active').length){
console.log('yes'); //always yes even when not revealed
} else {
//do nothing
}
</script>
//also tried if ($('#myModal').hasClass('someClass'))
EDIT
when active there is CSS of "visibility" : "visible", otherwise "hidden" so I tried the following, but it is not responding to the conditional. Any ideas why that might happen?
if($("#myModal").css("visibility", "hidden").length > 0) {
console.log('is hidden');
} else {
console.log('is shown');
}
This is the cookie code with Zurb's options for the reveal popup.
if (document.cookie.indexOf('visited=true') == -1) {
var tenYears = 3600 * 1000 * 24 * 365 * 10; //1000*60*60*24*15;//15days
var expires = new Date((new Date()).valueOf() + tenYears);
document.cookie = "visited=true;expires=" + expires.toUTCString() + ";path=/"; //encodeURIComponent +
// Zurb's popup reveal modal
$('#myModal').reveal({
animation: 'fadeAndPop',
animationspeed: 100,
closeonbackgroundclick: true,
dismissmodalclass: 'close-reveal-modal'
});
}