Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Jquery recuperare img da file

    Con jquery cerco di recuperare le img dal file getImages che risiede nella cartella ../chapter_06/08_ajax_image_gallery_improved/
    Però le immagini non si caricano.
    codice:
    var GALLERY =
    {
    	container: '#gallery',
    	url: '../chapter_06/08_ajax_image_gallery_improved/getImages',
    	delay: 5000,
    
    	load: function()
    	{
    		var _gallery = this;
    		jQuery.ajax(
    		{
    			type:"get", 
    			url: '../chapter_06/08_ajax_image_gallery_improved/getImages', 
    			beforeSend: function()
    			{
    				jQuery(_gallery.container)
    				.find('img')
    				.fadeOut('slow', function()
    				{	jQuery(this).remove();	});
    			},
    			success: function(data)
    			{
    				var images = data.split('|');
    				jQuery.each(images, function()
    				{	_gallery.display(this);	});
    			},
    			complete: function() {
    			setTimeout(function()
    			{
    				_gallery.load();
    			},
    			_gallery.delay);
    			}
    		});
    	},
    	display: function(image_url)
    	{
    		jQuery('<img></img>')
    		.attr('src', '../images/' + image_url)
    		.hide()
    		.load(function()
    		{
    			jQuery(this).fadeIn();
    		})
    		.appendTo('#gallery');
    	}
    }
    
    jQuery(document).ready(function(){
      GALLERY.load();
    });

  2. #2

    Re: Jquery recuperare img da file

    [QUOTE]Originariamente inviato da lucavalentino
    Con jquery cerco di recuperare le img dal file getImages che risiede nella cartella ../chapter_06/08_ajax_image_gallery_improved/
    Però le immagini non si caricano.
    codice:
    var GALLERY =
    {
    	container: '#gallery',
    	url: '../chapter_06/08_ajax_image_gallery_improved/getImages',
    	delay: 5000,
    
    	load: function()
    	{
    		var _gallery = this;
    		jQuery.ajax(
    		{
    			type:"get", 
                            url: this.url, 
    			beforeSend: function()
    			{
    				jQuery(_gallery.container)
    				.find('img')
    				.fadeOut('slow', function()
    				{	jQuery(this).remove();	});
    			},
    			success: function(data)
    			{
    				var images = data.split('|');
    				jQuery.each(images, function()
    				{	_gallery.display(this);	});
    			},
    			complete: function() {
    			setTimeout(function()
    			{
    				_gallery.load();
    			},
    			_gallery.delay);
    			}
    		});
    	},
    	display: function(image_url)
    	{
    		jQuery('<img></img>')
    		.attr('src', '../images/' + image_url)
    		.hide()
    		.load(function()
    		{
    			jQuery(this).fadeIn();
    		})
    		.appendTo('#gallery');
    	}
    }
    
    jQuery(document).ready(function(){
      GALLERY.load();
    });
    [/Un errore è quello in rosso.
    L'altro dovrebbe essere la versione di Jquery che ho usato.
    Con la 1.6 non fa con la 1.4 fa.

    Mi chiedo allora le differenze.

  3. #3
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    ma non si caricano o non le vedi?
    se ispezioni l' elemento ci sono o no?

    comunque setti l' src dell' immagine prima di settarne l' onload, che in javascript non e' corretto

    vedi differenze con la cache pulita o meno?
    browser in uso?

  4. #4
    Utilizzando firebug e qundi firefox mi da
    data.split is not a function
    Perchè

  5. #5
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    data non sara' una stringa
    cos'e'?

  6. #6
    Ho messo il tutto su altervista aggiungendo anche una immagine prima del caricamento dell'immagine.
    Codice PHP:
    var GALLERY = {
      
    container'#gallery',
      
    url'getImages',
      
    delay5000,
      
      
    load: function() {
        var 
    _gallery this;

        
    jQuery.ajax({ 
          
    type:"get"
          
    urlthis.url
          
    beforeSend: function() {
            
    // fade out and remove the old images
            
    jQuery(_gallery.container)
              .
    find('img')
              .
    fadeOut('slow', function() {
                
    jQuery(this).remove();
              });
            
    // add the spinner 
            
    jQuery('<div></div>')
              .
    attr('class''spinner')
              .
    hide()
              .
    appendTo(_gallery.container)
              .
    fadeTo('slow'0.6);
          },
          
    success: function(data){ 
            var 
    images data.split('|');
            
    jQuery.each(images, function() {  
              
    _gallery.display(this);
            });
          },
          
    complete: function() {
            
    setTimeout(function() {
              
    _gallery.load();
            }, 
    _gallery.delay);
            
    // remove the spinner 
            
    jQuery('.spinner').fadeOut('slow', function() {
              
    jQuery(this).remove();
            });
          }
        });
      },
      
    display: function(image_url) {
        
    jQuery('<img></img>')
          .
    attr('src''../../images/' image_url)
          .
    hide()
          .
    load(function() { 
            
    jQuery(this).fadeIn();
          })
          .
    appendTo('#gallery');
      }
    }

    jQuery(document).ready(function(){
      
    GALLERY.load();
    }); 
    Il problema è che l'immagine che indica il caricamento nel mio caso lo spinner si rivisualizza anche dopo che l'immagine sono caricate.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.