0

I'm using a jQuery plugin (link) to pull external pages into a div on my homepage, and each one of the external pages contains a jQuery-based horizontal gallery slider.

Example: http://www.iamtimothylong.com/example

You'll notice that when the external pages are loaded through the AJAX request (by clicking 'book one' or 'book two'), the horizontal slider within those external pages stops functioning.

However, the horizontal slider does work if statically placed in the div (just so it's clear that it's not a problem with the slider itself).

Anyone know a solution/workaround? One guy said

"You need to rebind the slider to the new elements after the XHR request has completed. Inside the success handler of your AJAX request, perform the mScrollBar() binding."

Unfortunately, I'm a programming ignoramus and I need it spelled out in laymen's terms. :)

And the AJAX loader source is located here: /js/menu.js

SnoringFrog
  • 1,479
  • 1
  • 16
  • 30

1 Answers1

0

I would say it is a classic case of replacing the event that is not firing with .live('event')

Basically when the javascript is fired and attaches event handlers when the page is loaded (or whenever they are called), it attaches them to currently existing elements that exist on the page at that time, so when you load in new content (via AJAX) those events are not attached to the new content events that have just been loaded and match the selector.

To fix this jQuery has a .live() event that matches any currently existing DOM elements AND future ones added dyamically.

jondavidjohn
  • 61,812
  • 21
  • 118
  • 158
  • Jon, thanks so much for the thorough answer. I did try to attach that handler to the events that I thought applied and am still having the issue (most likely due to an error on my end). If possible, take a look at the source for the slider and see if you have any input: http://www.iamtimothylong.com/example/js/jquery.mCustomScrollbar.js I imagine it will apply to both the mousewheel and the horizontal scroll. Thanks again! – Timothy Long Feb 06 '11 at 06:55
  • That link gives me a 404, which might be part of the problem. ;) – jondavidjohn Feb 06 '11 at 17:34