Image scroller

Discussion in 'JavaScript' started by cris02, Oct 17, 2006.

  1. #1
    hello,
    i downloaded a image scroller in this site --> http://www.fortochka.com/JavaScript/HorScroller/default.htm but i want to edit some of the code like placing on the link "OnClick" .. but i dont know how or where i put it.. thanks.. please help

    here's the code:

    
    <html>
    
    <head>
    <title>WPHAI</title>
    <Script>
    var pic = new Array()
    function banner(name, width, link){
       this.name = name
       this.width = width
       this.link = link
       }
    
    pic[0] = new banner('image/gal/DSC_0275.JPG',153,'image/gal/DSC_0275.JPG')
    pic[1] = new banner('image/gal/DSC_0279.jpg',153,'image/gal/DSC_0279.JPG')
    pic[2] = new banner('image/gal/DSC_0289.jpg',153,'image/gal/DSC_0289.jpg')
    pic[3] = new banner('image/gal/DSC_0294.JPG',153,'image/gal/DSC_0294.JPG')
    pic[4] = new banner('image/gal/DSC_0295.JPG',153,'image/gal/DSC_0294.JPG')
    
    var speed = 20
    
    var kk = pic.length
    var ii
    var hhh
    var nnn
    var myInterval
    var myPause
    var mode = 0
    var imgArray = new Array(kk)
    var myLeft = new Array(kk)
    for (ii=0;ii<kk;ii++){
    imgArray[ii] = new Image()
    imgArray[ii].src = pic[ii].name
    imgArray[ii].width = pic[ii].width
    
       hhh=0 
       for (nnn=0;nnn<ii;nnn++){
          hhh=hhh+pic[nnn].width
       }
       myLeft[ii] = hhh
    }
    
    function ready(){
       for (ii=0;ii<kk;ii++){ 
          if (document.images[ii].complete == false){
             return false   
             break
          }
       }
    return true
    }
    
    
    function startScrolling(){
       if (ready() == true){      
          window.clearInterval(myPause)
          myInterval = setInterval("autoScroll()",speed)   
       }
    }   
       
    
    function autoScroll(){
       for (ii=0;ii<kk;ii++){
          myLeft[ii] = myLeft[ii] - 1
          
       if (myLeft[ii] == -(pic[ii].width)){
          hhh = 0
          for (nnn=0;nnn<kk;nnn++){
             if (nnn!=ii){
                hhh = hhh + pic[nnn].width
             }         
          }
          myLeft[ii] =  hhh
       }
          
                
          document.images[ii].style.left = myLeft[ii]
       }
       mode = 1
    }
    
    function stop(){
       if (mode == 1){
          window.clearInterval(myInterval)
       }
       if (mode == 0){
          window.clearInterval(myPause)
       }   
    }
    
    function go(){
       if (mode == 1){
          myInterval = setInterval("autoScroll()",speed)
       }
       if (mode == 0){
          myPause = setInterval("startScrolling()",3000)
       }   
    }
    
    myPause = setInterval("startScrolling()",3000)
    </Script>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <body>
    <Script>
    for (ii=0;ii<kk;ii++){
    document.write('<a href = ' + pic[ii].link + ' target="_blank" ><img space=5 hspace=5 vspace=0 border=0 height=150 width=150 style=position:absolute;top:0;Left:' + myLeft[ii]  + '; src=' + pic[ii].name + ' onMouseOver=stop() onMouseOut=go()></a><br>')
    }
    </Script>
    </body>
    
    </html>
    
    Code (markup):

     
    cris02, Oct 17, 2006 IP
  2. coolsaint

    coolsaint Banned

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Dear cris02, what function you want to add on onclick?

    document.write('<a href = ' + pic[ii].link + ' target="_blank" >

    you have to modify this line and put onclick event inside the anchor. You can see the javascript will be creating a anchor by this line . Let me know what you want to put specific. I wish i can help.
     
    coolsaint, Oct 17, 2006 IP
  3. cris02

    cris02 Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    well, i just want to call another javascript to open popup window instead of "_blank" thanks
     
    cris02, Oct 17, 2006 IP
  4. coolsaint

    coolsaint Banned

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4

    Try this :

    document.write('<a href = ' + pic[ii].link + ' onclick="myfunction()"><img space=5 hspace=5 vspace=0 border=0 height=150 width=150 style=position:absolute;top:0;Left:' + myLeft[ii] + '; src=' + pic[ii].name + ' onMouseOver=stop() onMouseOut=go()></a><br>')

    I assume the myfunction calls the popup to open. I wish it will help.
     
    coolsaint, Oct 17, 2006 IP
  5. cris02

    cris02 Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    thanks for the reply.. i try your your suggestion gets me an error the image not appear. i try also this but error on page.
    
    document.write('<a href = "javascript:win(' + pic[ii].link + ')"><img space=5 hspace=5 vspace=0 border=0 height=150 width=150 style=position:absolute;top:0;Left:' + myLeft[ii]  + '; src=' + pic[ii].name + ' onMouseOver=stop() onMouseOut=go()></a><br>')
    
    Code (markup):
     
    cris02, Oct 17, 2006 IP