0

When I wasn't using the plugin to put ajax content into my scroll div, I could do this

$('.album').hover(function(){
    var id = $(this).attr('id');
    ajax request here
});

And every time I would hover over .album with a new id a different set of content would be the input specific to the id number. But I have to use the plugin to use ajax because it has to do other functions for the scroll to work.

So I try this:

$('.album').hover(function(){
        var id = $(this).attr('id');
        $("#makeMeScrollable").smoothDivScroll({
             getContentOnLoad: { 
             method: "getAjaxContent",
             content: "albumphotos.php?id="+ id,
             manipulationMethod: "replace"
             }
        });
}); 

Which works perfect and lets the scroll work. But then I scroll over to a different album with a different id it doesn't redo the request and stays with the same id and same content. What can I do?

user2127833
  • 179
  • 2
  • 5
  • 16

1 Answers1

1

You should initialize the plugin outside the hover function and use the public method getAjaxContent to replace the content:

$("#makeMeScrollable").smoothDivScroll();
// add the getContentOnLoad option if you need to get some content on page load

$('.album').hover(function(){
    var id = $(this).attr('id');
    $("#makeMeScrollable").smoothDivScroll("getAjaxContent", "albumphotos.php?id="+ id, "replace");
}); 
omma2289
  • 54,161
  • 8
  • 64
  • 68
  • Can't believe I forgot about this... wow thanks a ton Ive spent way too much time on this. If anyone wants more info http://www.smoothdivscroll.com/publicMethods.html#getAjaxContent – user2127833 Aug 16 '13 at 19:08
  • 1
    @user2127833 glad to help, as a rule of thumb you shouldn't try to initialize a plugin in an element multiple times (unless you destroy it every time) as you were doing in your hover function, most plugins should provide a way to call a method or update the options – omma2289 Aug 16 '13 at 19:12