javascript - How to insert array of images into swipebox gallery? -


this html code:

    <div class="profile-gallery">         <div class="profile-gallery_top js-bigimg">             <a href="img/bigimg1.jpg" class="swipebox">                 <img class="profile-bigimage" src="img/bigimg.jpg" alt=""/>             </a>         </div>         <ul class="profile-thumbs">             <li><img src="img/imgthmubs1.jpg" data-bigimage="img/bigimg1.jpg" data-original="img/origimg1.jpg" alt=""/></li>             <li><img src="img/imgthmubs2.jpg" data-bigimage="img/bigimg2.jpg" data-original="img/origimg2.jpg" alt=""/></li>             <li><img src="img/imgthmubs3.jpg" data-bigimage="img/bigimg3.jpg" data-original="img/origimg3.jpg" alt=""/></li>         </ul> </div> 

i have big image , under big image there 3 thumbnails. if user click second thumbnail, big image has changes second data-bigimage. , swipebox link has change second data-original image. same other images.

this solution switching images:

    jquery(document).ready(function( $ ) {     $('.profile-thumbs li').click(function(){         var imageurl = $(this).children('img').data('bigimage');         var imageorig = $(this).children('img').data('original');         $('.profile-bigimage').attr("src", imageurl);         $('.swipebox').attr("href", imageorig);     }); }); 

here code pushes images swipebox array:

$(function () { new app();  $('.swipebox').click(function(e) {     $.swipebox(imgs());     e.preventdefault(); });  function imgs() {     var th = $('.profile-thumbs li');     var arr = [];      for(var = 0; < th.length; i++) {         var obj = {};         var current = $(th[i]).find('img').attr('data-original');         obj['href'] = current;         arr.push(obj);     }     return arr; } 

});

the problem swipebox gallery starting swipe first image. how can change above code, shell swipe selected image?

you should use initialindexonarray option available in swipebox:

http://brutaldesign.github.io/swipebox/#options

full list of options:

<script type="text/javascript"> ;( function( $ ) {      $( '.swipebox' ).swipebox( {         usecss : true, // false force use of jquery animations         usesvg : true, // false force use of png buttons         initialindexonarray : 0, // image index init when array passed         hideclosebuttononmobile : false, // true hide close button on mobile devices         hidebarsdelay : 3000, // delay before hiding bars on desktop         videomaxwidth : 1140, // videos max width         beforeopen: function() {}, // called before opening         afteropen: null, // called after opening         afterclose: function() {} // called after closing         loopatend: false // true return first image after last image reached     } );  } )( jquery ); </script> 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -