Javascript help

Discussion in 'CycleChat Cafe' started by lifeson, 12 Apr 2010.

  1. lifeson

    lifeson New Member

    Anyone know any Javascript?

    I have a bit of code that shows a random header image each time the page is refreshed...
    <script language="JavaScript">
    var str="";
    var theImages = new Array() // do not change this

    theImages[0] = '$BASE_PATH$/Backgrounds/header_1.png'
    theImages[1] = '$BASE_PATH$/Backgrounds/header_2.png'
    theImages[2] = '$BASE_PATH$/Backgrounds/header_3.png'
    theImages[3] = '$BASE_PATH$/Backgrounds/header_5.jpg'
    theImages[4] = '$BASE_PATH$/Backgrounds/header_7.jpg'

    var j = 0
    var p = theImages.length;

    var preBuffer = new Array()
    for (i = 0; i < p; i++){
    preBuffer = new Image()
    preBuffer.src = theImages

    var whichImage = Math.round(Math.random()*(p-1));

    document.write('<div class="banners" style="text-align:center;"><img src="'+theImages[whichImage]+'"></div>');

    The images are based on a screen resolution of 1280 px wide, the alternative images need to fit a browser width of 1024px
    That works fine but I now want it to show a set of different images depending on the screen resolution. Is this possible?
  2. Bman

    Bman Veteran

    use this function :

    Then add an if statement, and your done ;)
  3. OP

    lifeson New Member

    I think I follow
    I'll give that a bash Thanks
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice