Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-08-2012, 04:45 PM   PM User | #1
dylanbaumannn
Regular Coder

 
Join Date: Feb 2012
Location: Nebraska, USA
Posts: 132
Thanks: 8
Thanked 19 Times in 19 Posts
dylanbaumannn is an unknown quantity at this point
Question .animation() Fadein / Fadeout issue

Hello!

I'm currently working on a site that has a detector that figures out how far you've scrolled (let's say 300px from the top) and then it applies a .animation() to a div.

The current issue is that it properly detects when you scroll down past the trigger and will play the animation, however when you scroll back UP past the trigger, it won't fade the div back out.


Code:
//VARABLES
	var top = $(document).scrollTop();
	var section5headline = $("#section5headline").offset(); // (trigger)


//section5 animation
		if (section5headline.top < (top+300) ) {
			$('#section5spot2').animate({opacity:1},2500);
		}

//section5 Reverse animation
		if (section5headline.top > (top+300) ) {
			$('#section5spot2').animate({opacity:0},2500);
		}
the current code causes the div to have a default opacity of 0 since it starts off above the trigger. Once scrolled below it it will NOT apply the opacity:1 animation.

Am I missing something?

Thanks ahead of time!

Last edited by dylanbaumannn; 05-08-2012 at 07:47 PM.. Reason: Extra Code deleted
dylanbaumannn is offline   Reply With Quote
Old 05-08-2012, 06:08 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Your code will result in a syntax error

Where does this line of code come from?
Code:
marginLeft:0},800);
devnull69 is offline   Reply With Quote
Old 05-08-2012, 07:47 PM   PM User | #3
dylanbaumannn
Regular Coder

 
Join Date: Feb 2012
Location: Nebraska, USA
Posts: 132
Thanks: 8
Thanked 19 Times in 19 Posts
dylanbaumannn is an unknown quantity at this point
Quote:
Originally Posted by devnull69 View Post
Your code will result in a syntax error

Where does this line of code come from?
Code:
marginLeft:0},800);
sorry about that, I have removed it. It was irrelevant
dylanbaumannn is offline   Reply With Quote
Old 05-08-2012, 10:52 PM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
I suppose you put your code into a .scroll() handler? This will result in a lot(!) of queued animations while you are scrolling, because at a certain point one condition will be true with every tiny move of the scrollbar. So you create tons and tons of queued animations ...

Try to include a boolean that stores the current status
Code:
//VARABLES
	var visible = false;

	var top = $(document).scrollTop();
	var section5headline = $("#section5headline").offset(); // (trigger)


//section5 animation
		if (section5headline.top < (top+300) && !visible) {
			$('#section5spot2').animate({opacity:1},2500);
                        visible = true;
		}

//section5 Reverse animation
		if (section5headline.top > (top+300) && visible) {
			$('#section5spot2').animate({opacity:0},2500);
                        visible = false;
		}
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Tags
opacity, scrolling, trigger

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:37 PM.


Advertisement
Log in to turn off these ads.