javascript - Using an if statement with a percentage in Jquery always returns false -


i've got small amount of code creates endless carousel. when it's done in pixels, works fine:

$('.left').click(function(){         $('.box').animate({left: '+=100'}, 100, function(){         var $last = $('.box').last();         if ($last.css('left') == '100px') {             $last.prependto('.container').before('\n\r');             $('.box').css('left','0px');         }     }); }); 

http://jsfiddle.net/tmyie/4cule/1/

but if change pixels percentages, not work , if statement false.

$('.left').click(function(){         $('.box').animate({left: '+=5%'}, 200, function(){         var $last = $('.box').last();         if ($last.css('left') == '5%') {             $last.prependto('.container').before('\n\r').hide().fadein();             $('.box').css('left','0%');         }     }); }); 

http://jsfiddle.net/tmyie/4cule/2/

would know why is? i'm working responsive layout, need keep percentages.

according jquery's documentation, .css() return computed value.

note computed style of element may not same value specified element in style sheet. example, computed styles of dimensions pixels, can specified em, ex, px or % in style sheet. different browsers may return css color values logically not textually equal, e.g., #fff, #ffffff, , rgb(255,255,255).

so may not compare percent value.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -