kswedberg / jquery-carousel-lite

A jQuery carousel plugin based on jCarouselLite by Ganeshji Marwaha
MIT License
177 stars 59 forks source link

trigger go event doesn't work with nested carousels #47

Open roscopeeco opened 9 years ago

roscopeeco commented 9 years ago

Hello

I have encountered a bug when trying to use the 'go' event with nested carousels.

When the trigger go event is executed for the child carousel - $('div.subcarousel').trigger('go', '0') - the go actually is applied to the parent carousel instead.

thanks Ross

kswedberg commented 9 years ago

@roscopeeco Thanks for the report. Can you point me to a URL where I can see the problem? If not, can you provide some HTML and the code you're using so I have something to work with as I debug this?

Thanks!

roscopeeco commented 9 years ago

Hi Karl Sorry for the delay but i didn't actually have a reply in my browser for some reason!

I've set up a fiddle here: http://jsfiddle.net/620rxe68/2/ Looks like the next,prev & go are not working

If you click 'next' on the parent then click on 'next'on the child - it actually goes to next on both the parent and child.

if you then click 'back' on the parent and then click 'go 0' on the child it goes to the first parent again

hope this helps

thanks

Ross

kswedberg commented 9 years ago

Thanks, @roscopeeco . I'll investigate as soon as I'm able.

kswedberg commented 9 years ago

Okay, I just took a quick look, and I saw that the problem was due to the parent's btnNext and btnPrev selectors being too general. Changing them to '.parent > .next' and `'.parent > .prev' should do the trick.

Here's a fiddle showing the fix: http://jsfiddle.net/wLg58d70/

By the way, you could also use a function (sorry I haven't documented that yet), returning the element you want to use. For example:

var parentoptions = {
  // ... 
  btnNext: function() {
    return $(this).children('.next');
  },
  btnPrev: function() {
    return $(this).children('.prev');
  }
};```
roscopeeco commented 9 years ago

Hi Karl

Thanks for the quick reply. Ah yes schoolboy error regarding the prev,next options BUT still got the issue with the child.trigger('go',0).

i've amended the original demo: http://jsfiddle.net/620rxe68/6/

Thanks

ross