Looping Assets.image demo script

a place to get help

Moderator: 1.2 Moderators

Forum rules
  • Every time you need help create a new thread (but please use the search function before, as your problem maybe has already been solved)
  • use code highlighting (help)
  • After your problem has been solved you have to rename the subject to "[solved] <Topicname>" AND set the Topic icon as solved (the green check)

Looping Assets.image demo script

Postby paddyohanlon on Sat Nov 22, 2008 1:24 am

I'm playing around with the Assets.image demo code, http://demos111.mootools.net/Asset.images. I want the images to start changing automatically and to loop, so I have a continuous slide show. I've removed the click events so the script runs when the page is loaded, but I have no idea how to get this to loop.

Here's what I have...

  1. window.addEvent('domready', function(){
  2.             var busy = false, timer, loadedImages = [], gallery = $('gallery'), progress = $('progress'), bar = $E('#progress .bar');
  3.            
  4.            
  5.             // Place all photos to be displayed in the header in this folder
  6.             var path = 'images/header-photos/';
  7.            
  8.            
  9.             // Enter the names of the images to be displayed here
  10.             var images = [
  11.                 path + 'header-photo-01.jpg',
  12.                 path + 'header-photo-02.jpg'
  13.             ];
  14.            
  15.            
  16.             gallery.setStyles({'opacity': 0, 'display': 'none'});
  17.             progress.setStyle('visibility', 'hidden');
  18.            
  19.        
  20.            
  21.                 if (!busy) {
  22.                    
  23.                     var galleryImgs = $$('#gallery img');
  24.                
  25.                    
  26.                     busy = true;
  27.                     progress.setStyle('visibility', 'hidden');
  28.                     gallery.setStyle('display', 'block');
  29.                     new Asset.images(images, {
  30.                         onProgress: function(i) {
  31.                             this.setStyles({
  32.                                 'position': 'absolute',
  33.                                 'opacity': 0,
  34.                                 'left': (gallery.getCoordinates().width / 2) - (this.width / 2),
  35.                                 'top': (gallery.getCoordinates().height / 2) - (this.height / 2)
  36.                             });
  37.                             loadedImages[i] = this;
  38.                             var percent = ((i + 1) * progress.getStyle('width').toInt()) / images.length;
  39.                             bar.setStyle('width', percent).setHTML(i + 1 + ' / ' + images.length);
  40.                         },
  41.                         onComplete: function() {
  42.                             progress.setStyle('visibility', 'hidden');
  43.                             var fx = $('gallery').effect('opacity').start(1);
  44.                             timer = 0;
  45.                             loadedImages.each(function(image, i) {
  46.                                 timer += 1500;
  47.                                 image.inject(gallery);
  48.                                 fx = function() {
  49.                                     var imgEffect = image.effect('opacity', {duration: 1500});
  50.                                     imgEffect.start(1).chain(function() {
  51.                                        
  52.                                     });
  53.                                    
  54.                                 }.delay(timer * 2);
  55.                             });
  56.                         }
  57.                     });
  58.                 };
  59.         }
  60.        
  61.         );
paddyohanlon
 
Posts: 1
Joined: Sat Nov 22, 2008 1:17 am

Return to Help

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest