自分自身にjqueryを教えようとしています。次のコードスニペットは正常に機能しますが、コードをより短く/より効率的にすることは可能だと思います。
//Alter the stylesheet to hide the contents of the page initially.
//When the page is loaded, fade in the contents slowly.
var backgroundBuffer;
$('p').mouseover(function() {
backgroundBuffer = $(this).css("background-color");
$(this).css({"background-color": 'yellow'});
}).mouseout(function(){
$(this).css({"background-color": backgroundBuffer});
});
「backgroundBuffer」をグローバルに宣言したくないのは、二度と使用しないからです。しかし、.mouseover()内で宣言すると、システムは後の.mouseout()でそれを認識しません。
//Alter the stylesheet to hide the contents of the page initially.
//When the page is loaded, fade in the contents slowly.
$('p').mouseover(function() {
var backgroundBuffer;
backgroundBuffer = $(this).css("background-color");
$(this).css({"background-color": 'yellow'});
}).mouseout(function(){
$(this).css({"background-color": backgroundBuffer});
});
あなたの助けのためのthx!