Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  permalink
    Any one know of some JS that'll rotate some images, similar to the way this site does. Notice, they're using flash, and I would rather not. Thanks.
    • CommentAuthorkaiman
    • CommentTimeSep 9th 2006 edited
     permalink
    I did a search on A List Apart and found this article as well as several others by Dan Benjamin: http://www.alistapart.com/articles/betterrotator/ This script uses php rather then javascript, but eliminates the worry about whether users have js enabled.

    Depending on your audience, you can also use javascript to do this as well by calling the images from an array.

    Something like this should do the trick. Just replace the paths to each image in the list below and add the number to the this variable: image = new StringArray(10) (i.e. replace the number 10 with the number of images you have and remember that counting in javascript always starts with 0 not 1).

    <script language="Javascript">
    <!--

    var currentdate = 0
    var core = 0

    function StringArray (n) {
    this.length = n;
    for (var i =1; i <= n; i++) {
    this[i] = ' '

    }
    }

    image = new StringArray(10)
    image[0] = 'images/PB010084-150.jpg'
    image[1] = 'images/PB150115-150.jpg'
    image[2] = 'images/PA240077-150.jpg'
    image[3] = 'images/WhiteHouse_RedRoof-150.jpg'
    image[4] = 'images/PA170049-150.jpg'
    image[5] = 'images/PB010084-150.jpg'
    image[6] = 'images/PB150115-150.jpg'
    image[7] = 'images/PA240077-150.jpg'
    image[8] = 'images/WhiteHouse_RedRoof-150.jpg'
    image[9] = 'images/PA170049-150.jpg'

    var ran = 60/image.length

    function ranimage() {
    currentdate = new Date()
    core = currentdate.getSeconds()
    core = Math.floor(core/ran)
    return(image[core])
    }

    document.write("<img src='" +ranimage()+ "'>")

    //-->
    </script>

    The core of this script uses javascripts built in math function to randomly display images:

    function ranimage() {
    currentdate = new Date()
    core = currentdate.getSeconds()
    core = Math.floor(core/ran)
    return(image[core])
    }

    You can also put this into a separate .js file and include it in your page ie: <script type="text/javascript" src="../scripts/rotator.js"></script> If this won't work for you do a search for javascript image rotator and I am sure you will find several other similiar tutorials/scripts.

    Hope that helps,

    kaiman
  2.  permalink
    Thanks Kaiman ... I might give that a go and see if it fits. Alex, muchos graciaas for the cross fade redux link this maƱana. I think that's exactly what I was looking for.
Add your comments
    Username Password
  • Format comments as (Help)