samedi 18 avril 2015

Alternative to jquery $(document).ready(handler) when using javascript page transitions

In a simple plugin for my wordpress, I wrote code that sets up click events as follows:



$(document).ready(function() {
$("#myButton").click(function() {
//do stuff
});
});


This code works as expected when I load the relevant page directly. However, the way users are expected to access the page is through a link in the theme header. I am not really sure how page transitions in the theme work, but the end effect is that whenever a link is clicked, some animation happens, the page fades out, and the new page fades in. The problem is that $(document).ready() does not fire when the new page fades in, so the click handlers do not function.


How can I change the code so that the click handlers are registered at the time the new page fades in?


If it's necessary to see how the theme works, I am using the Bridge Theme. A demo version of the theme is available here.


Aucun commentaire:

Enregistrer un commentaire