Thursday, 15 January 2015

javascript - Why does "($(this).css('opacity')==.3)" not work? -



javascript - Why does "($(this).css('opacity')==.3)" not work? -

i trying create if statement in jquery checks see if opacity .3, not work.

if ($(this).css('opacity')==.3) {$(this).fadeto(500,1);}

am formatting opacity incorrectly? tried 0.3 no avail.

background:

i'm working fade effect, objects fades in when scroll past , fades out when scroll up.

myfunkyside kindly showed me how here: fade in on scroll down, fade out on scroll - based on element position in window

myfunkyside's original jsfiddle: http://jsfiddle.net/b7qnrsrz/1/

in instance, fade goes 0 opacity 1 , back. want go .3 1 , instead.

i tried replace

if (objectbottom < windowbottom) { if ($(this).css('opacity')==0) {$(this).fadeto(500,1);} } else { //object goes out of view (scrolling up) if ($(this).css('opacity')==1) {$(this).fadeto(500,0);} }

with

if (objectbottom < windowbottom) { if ($(this).css('opacity')==.3) {$(this).fadeto(500,1);} } else { //object goes out of view (scrolling up) if ($(this).css('opacity')==1) {$(this).fadeto(500,.3);} }

but not work. here's effort on jsfiddle: http://jsfiddle.net/b7qnrsrz/3/

thanks taking @ this!

you else saying, or since you're dealing 2 case (positive/negative test), utilize ==1 , !=1, instead of ==.3. also, it's jquery, create sure utilize .stop() transitions/animations.

http://jsfiddle.net/b7qnrsrz/16/

javascript jquery css

No comments:

Post a Comment