LoginSignup
0
1

More than 3 years have passed since last update.

jQueryのanimate()で透明度を付けて背景色だけを変える

Posted at

背景色をふわぁーっと変えたい

animate()をつかう。

以下の例だと子要素まで透明にしてしまうので、文字も透明にしてしまう。
opacityってそういうやつなんだって。


$("#test").mouseover(function(){
  $(this).animate({ 
    backgroundColor: "#ffffff",
    opacity: 0.5
  }, 1000, 'linear');
});

文字を透明にせず、背景のみ半透明なものをアニメーションする

じゃあ、opacityを消して
#ffffff00 みたいな感じで透明度を付けようとしても反映されないンゴ。
そんな時は、rgb(0,0,225,0.5)的な感じにすると透明度が設定できるようになる。


$("#test").mouseover(function(){
  $(this).animate({ 
    backgroundColor: "rgb(0,0,225,0.5)"
    // opacity: 0.5 ← opacity は不要!
  }, 1000, 'linear');
});

そうすれば半透明の背景のみをアニメーションをつけて表示非表示できるようになる!文字も透明にならない!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1