Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
jquery animation speed based on size of DIV
Old 05-22-2009, 08:52 AM jquery animation speed based on size of DIV
Skilled Talker

Posts: 83
Trades: 0
Hello,

I am having a set of 150px width DIV's next to each other, that all animate as a whole from right to left. The amount of DIVs varies, and i want to have the animation look the same speed with 1 DIV or with 10.

Since each DIV is 150px width, i currently have the animation speed based on the amount of DIV's:
Code:
aantal = $('#scroller div').size();
var speed = 8000;
snelheid = speed * aantal;
 $('#scroller').animate({marginLeft: "-"+links+"px"}, snelheid, "linear");
#scroller is the container DIV that contains all 150px width DIVs.

I still notice that 1 DIV moves quite a bit faster then when i have 4 DIV's. How would i make the speed constant, no matter how many DIV's i have?

thanks!

Matt
killerwhale65 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-22-2009, 09:01 AM Re: jquery animation speed based on size of DIV
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Put one container around all the divs, then animate it instead of all of them individually. This will be a lot more efficient instead of relying on several separate animation registrations, which each rely on their own setInterval() internal to jQuery.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-22-2009, 10:23 AM Re: jquery animation speed based on size of DIV
Skilled Talker

Posts: 83
Trades: 0
that is how i did it. Sorry if i did not make myself clear: #scroller is the container DIV that contains all 150px width DIVs.
killerwhale65 is offline
Reply With Quote
View Public Profile
 
Old 05-22-2009, 10:37 AM Re: jquery animation speed based on size of DIV
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Not your fault, I just misunderstood.

What happens when you do this instead?

Code:
var speed = 8000;
speed *= $('#scroller div').length;
 $('#scroller').animate({marginLeft: "-"+links+"px"}, speed, "linear");
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-22-2009, 11:05 AM Re: jquery animation speed based on size of DIV
Skilled Talker

Posts: 83
Trades: 0
1 DIV is still a lot faster moving then 4 DIVs.

But i did this:
Code:
snelheid = speed +(2500*aantal);
instead of this:
Code:
snelheid = speed * aantal;
And now i see very little difference!
killerwhale65 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to jquery animation speed based on size of DIV
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23169 seconds with 12 queries