ajax+jQueryプラグインについて
現在ギャラリーサイトを制作しています。
ギャラリーサイトに便利な、jQueryプラグイン「lightgallery」( http://sachinchoolur.github.io/lightGallery/ )というプラグインを使用しています。
このプラグインで複数並んだ画像のスライドショーなどの機能を実装しています。
大量の画像なので、ajaxを使用し何枚かに分けて読み込んでいます。
img.html
<a class="inimg" href="画像パス"><img src="サムネイルパス"></a> <a class="inimg" href="画像パス"><img src="サムネイルパス"></a> ........
img2.html
<a class="inimg" href="画像パス"><img src="サムネイルパス"></a> <a class="inimg" href="画像パス"><img src="サムネイルパス"></a> ........
index.html
<html> <head> <script> jQuery(document).ready(function($) { $.ajax({ url: "img.html", dataType: "html", cache: false, success: function(data, textStatus) { $('.set').html(data); }, error: function(xhr, textStatus, errorThrown) { alert('Error! ' + textStatus + ' ' + errorThrown); } }); $('button').click(function() { $.ajax({ url: "img2.html", dataType: "html", cache: false, success: function(data, textStatus) { $('.set').append(data); }, error: function(xhr, textStatus, errorThrown) { alert('Error! ' + textStatus + ' ' + errorThrown); } }); }); jQuery(window).load(function() { $("#lightgallery").lightGallery(); //画像にlightgalleryプラグインを適用させる記述 }); </script> </head> <body> <div id="set"></div> <button>更に表示</button> </body>
少しわかりにくい記述で申し訳ないのですが上記のように記述しています。
imgタグに付いているinimgというクラスが付いている画像をスライドショーさせられるのですが、ajaxで新しく取得する画像には適用されません。
$('.set').append(data); ``` のつぎに
$("#lightgallery").lightGallery();
を書けば無理やり適用されるのですが、img.htmlとimg2.htmlの画像を続けてスライドショーできません。 結局何がやりたいかというと、 ・大量の画像なので、上記のように分けて複数の画像をajaxで読み込みたい ・新たに取得する画像を、既に取得している画像と続けてlightgalleryプラグインのスライドショーを適用させたい。 なにかいい方法はありますでしょうか? 本当にわかりにくく、Web制作初心者でお恥ずかしいですが お力お貸しいただければ幸いです。 よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。