I am trying to create an if statement in jquery that checks to see if the opacity is .3, but it does not work.
if ($(this).css('opacity')==.3) {$(this).fadeTo(500,1);}
Am I formatting the opacity incorrectly? I also tried 0.3
to no avail.
Background:
I'm working with a fade effect, where an objects fades in when you scroll past it and fades out when you scroll up.
myfunkyside kindly showed me how to do this here: Fade In on Scroll Down, Fade Out on Scroll Up - based on element position in window
myfunkyside's original jsfiddle: http://jsfiddle.net/b7qnrsrz/1/
In this instance, the fade goes from 0 opacity to 1 and back. I want to go from .3 to 1 and back instead.
I tried to 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 it does not work. Here's my attempt on jsfiddle: http://jsfiddle.net/b7qnrsrz/3/
Thanks for taking a look at this!