How do I add random images to a web page with or without the help of backstretch in jQuery

StackOverflow https://stackoverflow.com/questions/21579787

  •  07-10-2022
  •  | 
  •  

Question

This is the code that I am using, but it is not working when I run it:

  $(document).ready(function(){

             var lst_img = ["tab1.jpg",'tab2.jpg','tab3.jpg','tab4.jpg','tab5.jpg' 'tab6.jpg','tab7.jpg','tab8.jpg','tab9.jpg','tab10.jpg','tab11.jpg','tab12.jpg','tab13.jpg' 'tab14.jpg','tab15.jpg','tab17.jp','tab18.jpg','tab19.jpg'] 

           var loop = 0;
           var b = $('#img_container');
            var src = [];
        var len = lst_img.length;
       for (var i = 0; i <len; i++) {
            src[i] = $(#img_container).eq(i).attr('lst_img[i]');
            }

        setInterval(function() {


          // loop = (loop + 1) % len;
         $(b).backstretch(src, {
                     duration: 2000,
                     fade: 1750,
                     lazyload: true });
    });
});
Was it helpful?

Solution

I found two mistakes in your code first one is $('#img_container').backstretch(...) instead of this using like this what you doing is $($('#img_container')).backstretch(..) and second one is

for (var i = 0; i <len; i++) {
    src[i] = $(#img_container).eq(i).attr('lst_img['+i+']');
    }

apart from this i am not sure about your code... just try this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top