www.webdeveloper.com
Results 1 to 5 of 5

Thread: Fading Image Slideshow?

  1. #1
    Join Date
    Jul 2010
    Posts
    9

    Fading Image Slideshow?

    Hi, Does anybody know how to create an Image Slideshow like the one on the main page of http://www.game.co.uk?? I want it simple, don't want loads of script that half of it can be taken out.

  2. #2
    Join Date
    Jul 2008
    Location
    Europe
    Posts
    13

    Fading image slideshow

    Hi Fleewood,

    This is the code you would use if you choose Magic Slideshow:

    1. Add the JS and CSS to the <head>:

    Code:
    <link rel="stylesheet" type="text/css" href="magicslideshow.css"/>
    <script src="magicslideshow.js" type="text/javascript">
    2. Add a div with your images in it. e.g:

    Code:
    <div class="MagicSlideshow">
    <img src="example1.jpg"/>
    <img src="example2.jpg"/>
    <img src="example3.jpg"/>
    </div>
    3. Customize your slideshow by using over 30 parameters. e.g.:

    Code:
    <script type="text/javascript">
    MagicSlideshow.options = {
    'speed':'10',
    'pause':'hover',
    'arrows':'no'
    }
    </script>
    The code above will fade images every 10 seconds, pause it on mouse hover and hide the arrows.

    That's it.

    Now if you want to link each image to a URL, add an href to each image like do:

    Code:
    <div class="MagicSlideshow">
    <a href="example1.htm"><img src="example1.jpg"/></a>
    <a href="example2.htm"><img src="example2.jpg"/></a>
    <a href="example3.htm"><img src="example3.jpg"/></a>
    </div>
    More fading image options are here:

    http://www.magictoolbox.com/magicslideshow_integration/

  3. #3
    Join Date
    Jul 2010
    Posts
    9
    thats not what I wanted, but thanks anyway.
    Last edited by Fleewood; 07-21-2010 at 03:22 PM.

  4. #4
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,662
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    /*<![CDATA[*/
    #tst {
      position:relative;width:260px;height:200px;border:solid black 1px;
    }
    #tst IMG {
     width:100%;height:100%;
    
    }
    
    #tst1 {
      position:relative;width:260px;height:200px;border:solid black 1px;
    }
    #tst1 IMG {
     width:100%;height:100%;
    
    }
    
    /*]]>*/
    </style>
    
    </head>
    
    <body>
    <div id="tst">
     <img src="http://www.dynamicdrive.com/dynamicindex14/stadium.jpg" />
     <img src="http://www.dynamicdrive.com/dynamicindex14/winter.jpg" />
     <img src="http://www.dynamicdrive.com/dynamicindex14/duck.jpg" />
    </div>
    <input type="button" name="" value="Next" onclick="S1.Next(1);" />
    <input type="button" name="" value="Prev" onclick="S1.Next(-1);" />
    <input type="button" name="" value="Auto" onclick="S1.Auto();"/>
    <input type="button" name="" value="Pause" onclick="S1.Pause();"/>
    <input type="button" name="" value="GoTo 0" onclick="S1.GoTo(0);"/>
    <input type="button" name="" value="GoTo 1" onclick="S1.GoTo(1);"/>
    <input type="button" name="" value="GoTo 2" onclick="S1.GoTo(2);"/>
    <div id="tst1">
     <img src="http://www.dynamicdrive.com/dynamicindex14/stadium.jpg" />
     <img src="http://www.dynamicdrive.com/dynamicindex14/winter.jpg" />
     <img src="http://www.dynamicdrive.com/dynamicindex14/duck.jpg" />
    </div>
    <script type="text/javascript">
    /*<![CDATA[*/
    function zxcSS(o){
     var parent=document.getElementById(o.ID)                // the parent node of the images
     var imgs=parent.getElementsByTagName('IMG');            // the images in the parent node, the parent must be position 'relative' in the CSS
     this.ary=[];                                            // create a script instance array to store fade animator instances
     for (var z0=0;z0<imgs.length;z0++){                     // rotate through the images
      imgs[z0].style.position='absolute';                    // to allow the images to be placed on top of each other
      imgs[z0].style.zIndex=z0>0?'0':'1';                    // the first image is on top
      imgs[z0].style.left='0px';                             // all images have a position left of 0px
      imgs[z0].style.top='0px';                              // all images have a position top of 0px
      this.ary[z0]=new zxcFadeAnimator(imgs[z0],z0>0?0:100); // each field of this.ary contains a new instance for the fade animator with an image as its object
      this.ary[z0].opacity(z0>0?0:100);                      // set the opacity of the top image to 100 and the balance to 0
     }
     this.cnt=0;                                             // create a script instance counter this.cnt to 0
     this.lst=this.ary[0];                                   // create a script instance object referencing the top image
     this.ms=o.Duration||1000;                               // create a script instance recording the fade duration
     this.hold=o.Hold||this.ms*2;                            // create a script instance recording the automatic image change duration
    }
    
    zxcSS.prototype={
    
    // the instance 'GoTO' function
    // pass a number of the instance ary field to fade in that image
     GoTo:function(nu){
      clearTimeout(this.to);  // clear the timeout of the instance 'Auto' function
      if (this.ary[nu]){      // make sure the instance ary field exists
       this.cnt=nu;           // set the instance count to the number
       this.Next(0);          // call the instance 'NEXT' function passing 0 which will not increment the count
      }
     },
    
    // the instance 'Next' function
    // pass 1 or -1 to increment or decrement the intance count
     Next:function(ud){
      clearTimeout(this.to);                       // clear the timeout of the instance 'Auto' function
      this.lst.obj.style.zIndex='0';               // move the last image to the bottom
      this.lst.fade(this.lst.data[0],0,this.ms);   // fade out the last image
      this.cnt+=ud;                                // increment or decrement the intance count
      this.cnt=this.cnt<0?this.ary.length-1:this.cnt>=this.ary.length?0:this.cnt; // if the count is less than 0 set it to the maximum, if grater then the maximum set it to 0
      this.lst=this.ary[this.cnt];                 // change the instance lst to the new image
      this.lst.obj.style.zIndex='1';               // move the last image to the top
      this.lst.fade(this.lst.data[0],100,this.ms); // fade in the last image
     },
    
    // the instance 'Auto' function
    // to automatically change the images
     Auto:function(){
      clearTimeout(this.to); // clear the timeout of the instance 'Auto' function
      var oop=this;          // assign the instance to a local vaiable  to allow the setTimeout to function
      this.Next(1);          // call the instance 'Next' function  passing 1 to increment the count
      this.to=setTimeout(function(){ oop.Auto(); },this.hold+this.ms); // recall 'Auto' after the 'hold' plus 'fade' duration
     },
    
     Pause:function(){
      clearTimeout(this.to);
     }
    
    }
    
    
    // Opacity Fade Animator
    function zxcFadeAnimator(obj,srt){
     this.obj=obj;            // the instance object
     this.data=[srt];         // and array the current, start and finish value of opacity
     this.to=null;
    }
    
    zxcFadeAnimator.prototype={
    
    // instace function 'fade'
    // to start a fade in or fade out
    // parameter 0 = the fade start value.  (digits)
    // parameter 1 = the fade finish value. (digits)
    // parameter 0 = the fade duration.     (digits)
     fade:function(srt,fin,ms){
      clearTimeout(this.to);         // stop the instance setTimeout
      this.data=[srt,srt,fin];       // assign the current, start and finish value of opacity
      this.ms=ms*1;                  // the duration of the effect
      this.srt=new Date().getTime(); // the start time of the change
      this.change();                 // start the change
     },
    
    // instance function 'change'
    // to control the change of fade in or fade out
     change:function(){
      var oop=this;                                                      // assign the instance to a local vaiable  to allow the setTimeout to function
      var ms=new Date().getTime()-this.srt;                              // the current time minus the start time
      this.data[0]=(this.data[2]-this.data[1])/this.ms*ms+this.data[1];  // increment the current value dependent on the start and finish values and elapsed time
      this.opacity(this.data[0]);                                        // set the opacity to the current value
      if (ms<this.ms){                                                   // if the elapsed time is less than the 'fade duration' recall function opac
       this.to=setTimeout(function(){oop.change()},10);
      }
      else {
       this.data[0]=this.data[2];                                        // set the current value to the finish value
       this.opacity(this.data[0]);                                       // set the opacity to the current value(finish value)
      }
     },
    
    // instance function 'opacacity'
    // to control the change of fade in or fade out
     opacity:function(opc){
      opc=opc<0?0:opc>100?100:opc;
      var obj=this.obj;
      obj.style.filter='alpha(opacity='+opc+')';
      obj.style.opacity=obj.style.MozOpacity=obj.style.WebkitOpacity=obj.style.KhtmlOpacity=opc/100-.001;
     }
    
    
    }
    
    
    /*]]>*/
    </script>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    // generatate a new instance of the script.
    var S1=new zxcSS({
     ID:'tst',      // the unique ID name of the images parent node.                 (string)
     Duration:1000, // (optional) the duration of the fade effect in milliseconds.   (digits, default = 1000)
     Hold:2000      // (optional) the hold duration of automatic changing of images. (digits, default = Duration*2)
    });
    
    var S2=new zxcSS({
     ID:'tst1',      // the unique ID name of the images parent node.                 (string)
     Duration:500, // (optional) the duration of the fade effect in milliseconds.   (digits, default = 1000)
     Hold:2000      // (optional) the hold duration of automatic changing of images. (digits, default = Duration*2)
    });
    
    S2.Auto();
    
    /*]]>*/
    </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/

  5. #5
    Join Date
    Jul 2010
    Posts
    9
    thanks vwphillips.

Thread Information

Users Browsing this Thread

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

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