Connecting Tech Pros Worldwide Forums | Help | Site Map

Need help with a javascript transition

Newbie
 
Join Date: Sep 2007
Posts: 7
#1: Sep 21 '07
So I was on here the other day looking for help with the getElementByName method and recieved excellent help quickly. (Thankyou GITS) Now, I'm looking for some help with making some dynamic content transition (every 4 seconds).
Essentially what I have is 5 hidden divs in a php page. In my javascript code they get stored into an array and the setTimeout method is used to call then them one after the other. Instead of just having them switch I would like them to have an animated transition (a vertical push to be exact). The js code is listed below and the website to view this code is www.thenicheplayers.com
Expand|Select|Wrap|Line Numbers
  1. // Rotating headlines
  2.  
  3. var headlines = [];
  4. var idx = -1;
  5.  
  6. function get_headline_containers() {
  7.     var all_divs = document.getElementsByTagName('div');
  8.     var hdl_divs = [];
  9.  
  10.     for (var i = 0; i < all_divs.length; i++) {
  11.         var div = all_divs[i];
  12.  
  13.         if (div.className == 'headline') {
  14.             hdl_divs.push(div);
  15.         }
  16.     }
  17.  
  18.     return hdl_divs;
  19. }
  20.  
  21. function display_headline(idx) {
  22.     for (var i = 0; i < headlines.length; i++) {
  23.         headlines[i].style.display = i == idx ? 'block' : 'none';
  24.     }
  25. }
  26.  
  27. function rotate_headlines() {
  28.     idx++;
  29.  
  30.     if (idx >= headlines.length) {
  31.         idx = 0;
  32.     }
  33.  
  34.     display_headline(idx);
  35.  
  36.     window.setTimeout(function() {
  37.         rotate_headlines();
  38.     }, 4000);
  39. }
  40.  
  41. function init_page() {
  42.     headlines = get_headline_containers();
  43.     rotate_headlines();
  44. }

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Sep 21 '07

re: Need help with a javascript transition


Heya, Scooby.

Please use CODE tags when posting source code:

[CODE=javascript]
JavaScript code goes here.
[/CODE]
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Sep 23 '07

re: Need help with a javascript transition


What do you mean by a vertical push? Could you give an example?
Newbie
 
Join Date: Sep 2007
Posts: 7
#4: Sep 24 '07

re: Need help with a javascript transition


http://elouai.com/javascript/javascript-transitions-6.php

If you scroll halfway down the page theirs buttons in two columns. Left hand side, the second one says "transition Slide push". It works if youre using IE but not Firefox. Thats the kind of animation Im looking for but the stipulations are:
1) It would be pushed down, instead of pushed to the left
2) It would have better browser compatibility (ie IE, Firefox, and Safari)
3) It would go every 4 seconds, as called out by the setTimeout method in the code above.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,134
#5: Sep 24 '07

re: Need help with a javascript transition


hi ...

may be you want to have a look at the mootools ... goto the demo page and have a look at the slide transitions ... perhaps you will find what you are looking for ...

kind regards
Reply