Psygno
Psygno

Reputation: 261

Make a jQuery event happen once

I'm making a wordpress template. Imagine I have a that contains a menu bar with

$(document).ready(function() {
      $('#menu').hide();
      $('#menu').slideToggle("slow");
});

my menu slide down (it's a vertical menu), when the page loads... but, everytime I load a new static page in wordpress (pageid=1 etc), the page reload itself and so the event restart and the menu slide down again every time I press a link in the website!

How can I make the menu sliding animation happends one time? maybe only when I hit the home button and not all the pages?

Upvotes: 0

Views: 82

Answers (2)

user1576978
user1576978

Reputation: 1755

You could make this event happen only in your site's homepage, like:

<?php
if (is_home()):
?>
<style type="text/javascript">
$(document).ready(function() {
      $('#menu').hide();
      $('#menu').slideToggle("slow");
});
</style>
<?php endif; ?>

but if you want the user to see the animation even when he enters by any other page, you'll probably need some cookies ;P

Upvotes: 1

Crsr
Crsr

Reputation: 624

set a session variable $_SESSION['opened']==1; only on homepage

in header where is that jquery code:

<?php if(isset($_SESSION['opened']) && $_SESSION['opened'] == 1): ?>

your jquery code

<?php endif; ?>

In the rest of the pages, set that variable 0

Upvotes: 1

Related Questions