2つのJQuery関数を作成したいと思います。一方は、もう一方の関数で作成されたデータを使用します。言う:
jQuery.fn.myScroller = function (child) {
var $moveable = this.children(child);
var $children = this.children(child).children();
posl = posl.replace('px', '');
post = post.replace('px', '');
var varList = [];
$children.each(function () {
var currVar = {};
currVar.w = $(this).width();
varList.push(currVar);
});
// I want to save varList variable somehow.
this.varList = varList; // (1)
};
jQuery.fn.scrollUnitLeft = function () {
// Now I need to use this varList if this function called
// But the following returns undefined.
// However, I've saved it inside this at (1)
console.log(this.varList)
// More code...
}
$('#main_div').myScroller("#dummydiv");
$('#main_div').scrollUnitLeft();
コードのコメントで説明したように、これは機能しません。
これどうやってするの?