jquery - Tigerstipe rollover conundrum -
so have list of divs have alternating background colors through jquery. these have rollovers change background color. problem is, rollover function allows me animate class 1 background color on mouseout, said before, have alternating background color. how can handle in jquery? code below attempt @ if, else statement , odd, don't know proper syntax.
$(document).ready(function() { $('.whycapad_staff:even').css({"background-color":"#eaebeb"}); $('.whycapad_staff').hover(function() { $(this).stop().animate({"background-color":"#5facf8"}, 300); }, function(){ if ($(this = ':even')){ $(this).stop().animate({"background-color":"#eaebeb"}, 300) }; else { $(this).stop().animate({"background-color":"#ffffff"}, 300) } }) })
just use css:
.whycapad_staff:nth-child(even) { background-color:#eaebeb; } .whycapad_staff:hover { background-color:#5facf8; }
demo: http://jsfiddle.net/maniator/npwnm/
here example if want use jquery: http://jsfiddle.net/maniator/npwnm/5/
$(function() { //jquery fallback $('.whycapad_staff').hover(function() { $(this).data('b-color', $(this).css('background-color')); $(this).css('background-color', '#5facf8'); }, function() { $(this).css('background-color', $(this).data('b-color')); }); });
full fallback: http://jsfiddle.net/maniator/npwnm/9/
$(function() { //jquery fallback $('.whycapad_staff').each(function(index, item){ if(index%2 == 1){ $(this).css('background-color', '#eaebeb'); } }); $('.whycapad_staff').hover(function() { $(this).data('b-color', $(this).css('background-color')); $(this).css('background-color', '#5facf8'); }, function() { $(this).css('background-color', $(this).data('b-color')); }); });
Comments
Post a Comment