-4

I have logo in different colors. I want to make that on each hover images change. Default image is black, then hover1 image is red, hover2 image is yellow, hover3 image is blue. And then again starting from black and so on. Any ideas?

Thanks for help

Developer Desk
  • 2,294
  • 8
  • 36
  • 77
Merkley
  • 93
  • 1
  • 7

2 Answers2

2

DEMO: http://jsfiddle.net/FKAcs/

var logos = ["http://placekitten.com/100", "http://placekitten.com/200", "http://placekitten.com/300"];

var i = 0;

$('#logo').mouseover(function () {
    $(this).attr('src', logos[++i % logos.length]);
});

Essentially this maintains a counter (i) which increases on every mouseover event.

Based on the value of this counter we show the corresponding item in our logo array.

gvee
  • 16,732
  • 35
  • 50
1

Try this : DEMO HERE

var images=['https://www.gravatar.com/avatar/8a5b9d17248e0a9b953c0d5b94a9f2cb?s=128&d=identicon&r=PG','https://www.gravatar.com/avatar/7512241adf8b7fb3e19c19c06f775ee3?s=128&d=identicon&r=PG','https://www.gravatar.com/avatar/de2ea38f6a28646832eafb034951a982?s=128&d=identicon&r=PG'];

var counter=0;
$('#box').mouseenter(function(){
 $(this).attr('src',images[counter]);
 counter++;
 if(counter==images.length) counter = 0 ;
})
Charaf JRA
  • 8,249
  • 1
  • 34
  • 44