jsor / jcarousel

Riding carousels with jQuery.
https://sorgalla.com/jcarousel/
MIT License
1.99k stars 734 forks source link

Have support dynamic creating jcarousel? #816

Closed sjpeng closed 7 years ago

sjpeng commented 7 years ago

if possible support dynamic create? e.g.

var str = `<div class="form-group">
                <h3>Test</h3>
                <div class="jcarousel-wrapper">
                    <div class="jcarousel">
                        <ul>
                            <li class="text-center"><img src="img1.jpg"><label>test</label></li>
                        </ul>
                    </div>
                    <a href="#" class="jcarousel-control-prev">&lsaquo;</a>
                    <a href="#" class="jcarousel-control-next">&rsaquo;</a>
                    <p class="jcarousel-pagination"></p>
                </div>
               </div>`;
$('#test').append(str);
jsor commented 7 years ago

Doesn't that work for you?

//...
$('#test').append(str).find('.jcarousel').jcarousel();
sjpeng commented 7 years ago

yes! look like it's work, but I couldn't used prev/next button and picture doesn't cycle.

jsor commented 7 years ago

Yes, you need to use the control and autoscroll plugins.

sjpeng commented 7 years ago

Thank you, Is working! BTW, if possible more interactive when I click image? It can work before dynamically create jcarousel.

$('img').on('click', function(e){ 
     console.log('click!');
});
jsor commented 7 years ago

You can do that with delegated events:

$(document).on('click', '.jcarousel img', function(e){ 
     console.log('click!');
});
sjpeng commented 7 years ago

ok, thank you a lot.