順序付けられていないリストのリスト項目からオブジェクトを作成する際に小さな問題があります。ギャラリーを作成していますが、各ギャラリーのサムネイルを独自のオブジェクトにする必要があるため、jQuery の $.each() を使用して各リスト項目を反復処理しています
問題は、各 object/li に独自のインスタンス名を付ける方法がわからないことです。
コードは次のとおりです。
function galleryButton(){
this.link
this.name
this.image
this.identifier,
this.goPage = function(){
$('.container').animate({opacity : '0'}, 500).load(this.link + ' .galContainer', function(){$('.container').animate({opacity : '1'})});
return false;
}
}
$(document).ready(function(){
$.ajaxSetup({
cache:false
});
$('.gallery li a').each(function(node, value){
this = new galleryButton();
this.link = $(this).attr('href');
this.name = $(this).attr('name');
this.image = $(this + " img").attr('src');
this.identifier = $(this).attr('data-pic-id');
$(this).click(this.goPage);
})
$('.goback').click(function(){
var back = $(this).attr('href');
$('.container').animate({opacity : '0'}, 500).load(back + ' .gallery', function(){$('.container').animate({opacity : '1'})});
return false;
});
});