0
変数 "theOffset"を "localScroll"関数の中で動作させるにはどうすればよいですか?javascript変数のスコープで助けてください
jQuery(function($){
//initialize variable "theOffset"
theOffset = 10; // <-- sets variable for inside of "localScroll" function
$(window).resize(function() {
theOffset = 20; // <-- does NOT reset inside "localScroll" function
}); // end of window resize
$.localScroll({
target: '#content',
duration:1500,
hash:true,
offset: {top:0, left: theOffset}, // <-- I want to reset this on window resize
onBefore:function(e, anchor, $target){
},
onAfter:function(anchor, settings){
}
});
});
あなたがグローバルスコープになりたくないすべての変数の前に 'var'を置く必要があります。 – mpen
あなたは既存の質問を編集することができますhttp://stackoverflow.com/questions/4219478/javascript-variable-not-working-why新しい内容で、同じ問題で新しい質問を開始する必要はありません。 –
aaahh。私はまだstackoverflowの方法を学んでいます。 – Dave