www.webdeveloper.com
Results 1 to 2 of 2

Thread: image slide

  1. #1
    Join Date
    Nov 2013
    Posts
    44

    image slide

    i am trying to slide image in a window one after another.But this code seems not working.what could be the possible corrections to this code
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    
    <style>
    #holder{
    width:300px;
    height:300px;
    position:relative;
    margin:0 auto;
    border:1px solid black;
    top:200px;
    }
    img{
    	width:300px;
    height:300px;
    }
    </style>
    <script>
    var get=["image1.jpg","image2.jpg","image3.jpg"];
    var i=0;
    function begin(){
    	
    	var d=document.getElementById("give");
    	
    	for(i=0;i<3;i++){
    	
    	       d.setAttribute("src",get[i]);
    	
    	}
    	
    }
    setTimeout(begin,1000);
    </script>
    </head>
    
    <body>
    
    <div id="holder" ><img  src="" id="give"></div>
    <script>begin()</script>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,680
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    
    <style>
    #holder{
    width:300px;
    height:300px;
    position:relative;
    margin:0 auto;
    border:1px solid black;
    top:200px;
    }
    img{
    	width:300px;
    height:300px;
    }
    </style>
    <script>
    var get=["http://www.vicsjavascripts.org.uk/StdImages/1.gif","http://www.vicsjavascripts.org.uk/StdImages/2.gif","http://www.vicsjavascripts.org.uk/StdImages/3.gif"];
    
    function begin(id,ary,ms){
    	var o=begin[id],d=document.getElementById(id);
        if (d&&ary instanceof Array){
         if (!o){ // create a function begin object with a name if the id to record the count
          o=begin[id]={n:-1};
         }
         clearTimeout(o.to);
         o.n=++o.n%ary.length;
         d.src=ary[o.n];
         o.to=setTimeout(function(){ begin(id,ary,ms); },ms);
        }
    
    }
    </script>
    </head>
    
    <body>
    
    <div id="holder" ><img  src="" id="give"></div>
    <script>begin("give",get,2000)</script>
    </body>
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles