简体   繁体   中英

Image carousel slider not working bxSlider

This is how my carousel shows up as

在此处输入图片说明

in my code ive included

<!-- bxSlider CSS file -->
        <link rel="stylesheet" href="<c:url value="/resources/css/jquery.bxslider.css" />" type="text/css" />
        <script type="text/javascript" language="javascript" src="<c:url value="/resources/js/jquery.js" />"></script>
        <!-- bxSlider Javascript file -->
        <script type="text/javascript" language="javascript" src="<c:url value="/resources/js/jquery.bxslider.js" />"></script>

Im dynamically inserting my images into the ul tag

<ul class="bxslider" id="img_carousel"/> 


                                     var img_data='data:image/jpeg;base64,' + base64Encode(data);
                     $("<li>", { html: '<img style="width:55px;height:55px" src="' + img_data + '"/>' }).appendTo("#img_carousel"); 

and after this im calling

  $('.bxslider').bxSlider();

this is how my html looks like 捕获

how do i fix this?

I can't say for sure, but it could be because the .bxSlider() function is running before the images are populated in the ul

My suggestion would be to try this:

setTimeout(function(){
    $('.bxslider').bxSlider();
},500);

of course, 500 could be too long, if it does work, I'd try bringing it down to 10 and going up until you get good performance. Also, timeout could be tricky when dealing with a really slow internet connection, like 3G or dialup, in which case you might need some more complicated code to know exactly when images are done loading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM