多くの画像のスワイプ可能なスライドショーを作成しようとして、Swipe.jsとlazyloader.jsの 2 つのプラグインをつなぎ合わせようとしています。Swipe プラグインのスライドショー タイマー イベントで、Lazyloader 内の update 関数を呼び出したいと考えています。調査の結果、私の問題は namespace の 1 つに見えるようです。つまり、Swipe は Lazyloader 内のものを認識していないため、関数を呼び出すことができません。
- 次のコードが与えられた場合、私は自分の問題を正しく理解していますか?
- もしそうなら、どうすれば Swipe に Lazyloader の機能にアクセスさせることができますか?
ありがとうございました。
フォローアップ: Cheeso との Q&A の後、最終的に何が必要かについて、私が間違った質問をしていたことに気付きました。私の悪い質問のために将来の読者が混乱するのを避けるために、このコメントを追加します. これは、名前空間に関するものでも、プライベート関数へのアクセスに関するものでもありません。これは行うべきではありません。このスレッドは、自分が何をしているのか本当にわからない場合に、フランケンシュタイン ライブラリを一緒に試すことがいかにお勧めできないかについての最終的なスレッドです。; ) フォローアップを終了
swipe.js のコールバック:
this.callback = this.options.callback || function() {
HTML内で呼び出されるスクリプト:
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.lazyload.js" type="text/javascript"></script>
<script src='js/swipe.js' type="text/javascript"></script>
<script type="text/javascript">$(document).ready(function() {
function myAlert(){
//call a function from inside jquery.lazyload.js
alertMe();
}
//instantiate a swipe object and pass in a bunch of
//options, especially "callback" which fires on every slide change
window.mySwipe = new Swipe(document.getElementById('slider1'), {
startSlide: 0,
speed: 1000,
auto: 5000,
callback: function(){
myAlert();
}
});
// run lazyload on every VISIBLE image with the class "lazy" on load, and on every click
$("img.lazy").lazyload({event: "click", effect : "fadeIn", threshold: 0,});
});
</script>
jquery.lazyloader.js:
//outside of the container below, I can be called by myAlert()
function alertMe() {
alert("it worked!");
}
(function($, window) {
$window = $(window);
$.fn.lazyload = function(options) {
///
///Here be a bunch of lazyloader stuff
///
//I work when above, but once I am inside this container, I cannot be called by myAlert(),
//and I will error as 'not a valid function'
function alertMe() {
alert("it worked! Even inside of this container! ");
}
})(jQuery, window);