javascript - How to addClass and removeClass with fade via jQuery? -


i'm trying fade 1 image another. tried css route making top image transparent on hover, that's not going work in case. in case, on hover, i'm trying fade logo logo glow. logos aren't perfect shape, having 2 pictures on top of 1 redundant, since user can see "over" picture, aka logo glow, without hovering on it.

i found jquery's addclass , removeclass , thought that'd work. far, has, except fading isn't occurring. instead, it's switching on-hover image.
here's fiddle of code, except logo has been replaced apple , over-logo has been replaced orange, since logo pictures locally stored.

the javascript have in fiddle this:

$(document).ready(function() {     $('img#logo').hover(    function(){ $(this).stop(true).addclass('over', 500) },    function(){ $(this).stop(true).removeclass('over', 500) }); }); 

and here html:

<img id="logo" class="top" width="256" height="256" /> 

and css:

img.top {     background-image: url('https://pbs.twimg.com/profile_images/3588564988/ca2ec46372bf01eff59044dd0046132c.jpeg'); }  img.over {     background-image: url('http://icons.iconarchive.com/icons/gcds/chinese-new-year/256/orange-icon.png'); } 

thoughts? thanks!

try using transition

#logo{     transition: background-image 2s;     -moz-transition: background-image 2s;     -webkit-transition: background-image 2s; } 

demo: fiddle


since background-image transition supported in chrome now, try fadeout()

<div id="logo" class="top" /> 

then

#logo {     width:256px;     height:256px;     background-image: url('https://pbs.twimg.com/profile_images/3588564988/ca2ec46372bf01eff59044dd0046132c.jpeg'); } #logo.over {     background-image: url('http://icons.iconarchive.com/icons/gcds/chinese-new-year/256/orange-icon.png'); } 

and

$(document).ready(function () {     $('#logo').hover(function () {         $(this).stop(true, false).fadeto(500, .1, function () {             $(this).addclass('over').fadeto(500, 1)         })     }, function () {         $(this).stop(true, false).fadeto(500, .1, function () {             $(this).removeclass('over').fadeto(500, 1)         })     }); }); 

demo: fiddle


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -