Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Basic rotator script

    Well, I am a newbie really and I wanted to share a very basic barebones mini script for rotating content using basic DOM functionality in JS.

    Code:
    <p id="rotation"></p>
    <script>
    //place images, text, or html in the spinArray quotes
    var spinArray = [":D", ":O", ";)", ":)"];
    
    //the stereotypical random number generation string
    var randomnumber=Math.floor(Math.random()*4)
    
    //pass the spinArray data to the inside of the HTML tag with the Id of "rotation" and pass randomnumber to pass a random number between 0 and 3. 
    document.getElementById("rotation").innerHTML = spinArray[randomnumber];
    
    </script>
    I know, newbie script but I figure someone will find this useful to copy and paste into a website for banner rotation or something. I remember this being more lengthy back in 1998 for some reason!

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    901
    Thanks
    0
    Thanked 118 Times in 117 Posts
    Code:
    document.getElementById("rotation").innerHTML = spinArray[Math.floor(Math.random()*spinArray.length)];


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •