0
こんにちは、私はJavaScript /プログラミングの新機能であり、各フォトギャラリーにパラメータを与える担当スクリプトの合理的な解決策を見つけることができません。スクリプトは正常に動作していますが、私が書いたように、パラメータを何も繰り返さないように単純化することができます。 1つのパラメータ(クラスセレクタ)が各ギャラリースクリプトから変更されています。スクリプトJQueryギャラリー、関数のパラメータとしてCSSクラスを渡す
$(document).ready(function() {
$('.popup-gallery-wakipo').magnificPopup({ // HERE THE CLASS SELECTOR
delegate: 'a.gallery_portf',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '',
titleSrc: function(item) {
return item.el.attr('title') + '';
}
}
});
$('.popup-gallery-instacash').magnificPopup({ // HERE THE CLASS SELECTOR
delegate: 'a.gallery_portf',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '',
titleSrc: function(item) {
return item.el.attr('title') + '';
}
}
});
等...
は、そこで問題は、単にパラメータとしてそのクラスセレクタを渡すために、このスクリプトをモジュール化する方法です。たぶん、オブジェクトコンストラクタ/メソッドで、私が試してみたが、私は迷うことが
function Gallery (theclass){
$('.' + theclass).magnificPopup({
delegate: 'a.gallery_portf',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1]
},
image: {
tError: '',
titleSrc: function(item) {
return item.el.attr('title') + '';
}
}
});
}
var mySecondGallery = new Gallery("popup-gallery-wakipo");
mySecondGallery();
申し訳ありませんが、私はこのように使用しており、動作していません。ここにオリジナルのJSファイルhttp://pastebin.com/tM002P5U – Dedalos01
jQueryオブジェクトにアクセスする必要がありますか、コードが実行されるだけで十分ですか? – patrickcipot
ギャラリーを使っているJSライブラリがわかりません: - /、私はこのスクリプトが動作することを知っています。そしてあなたがラス・ラインに書いたその割り当ては何とか呼び出される必要はありませんか?ここギャラリーのHTML:http://pastebin.com/bqWATSpv 4行目のクラスを見つけよう – Dedalos01