2011-09-15 3 views
0

Je suis en train de charger une fonction jquery innerfade à l'intérieur d'un contenu chargé par la fonction jquery .load, j'ai vu de nombreux sujets similaires à cela, mais comme je suis très nouveau à javascript je ne peux pas obtenir la bonne solution.Jquery innerfade inside contenu ajaxed

Ce script que j'utilise pour charger le contenu:

$(document).ready(function() { 

// Check for hash value in URL 
var hash = window.location.hash.substr(1); 
var href = $('.nav li a').each(function(){ 

    var href = $(this).attr('href'); 
    if(hash==href.substr(0,href.length-5)){ 
     var toLoad = hash+'.php #content'; 
     $('#content').load(toLoad) 
    } 
}); 

$('.nav li a').click(function(){ 

var toLoad = $(this).attr('href')+' #content'; 
$('#content').hide('fast',loadContent); 


$('#load').remove(); 
$('#sub_corpo').append('<span id="load">sto caricando il contenuto...</span>'); 
$('#load').fadeIn('normal'); 
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5); 



function loadContent() { 
    $('#content').load(toLoad,'',showNewContent()) 

} 
function showNewContent() { 
    $('#content').show('normal',hideLoader()); 


} 
function hideLoader() { 
    $('#load').fadeOut('normal'); 
} 
return false; 

}); 

});

et c'est la fonction innerfade:

<script > 
function(){ 

$('#slideshow').innerfade({ 
     speed: 4500, 
     timeout: 6000, 
     type: 'sequence', 
     containerheight: '480px' 
     }); 
} 
</script> 

Je ne sais pas comment appeler cette fonction lorsque le contenu est chargé. J'apprécie vraiment votre suggestion.

Dimtiri

Répondre

0

Cela devrait être la réponse:

$('#content').load(toLoad, function() { 
    $('#slideshow').innerfade({ 
     speed: 4500, 
     timeout: 6000, 
     type: 'sequence', 
     containerheight: '480px' 
     }); 
}); 
+0

Merci Shawn mais ça ne marche pas ... – Dimitri

0

vous remercie de votre suggestion, je l'ai testé, mais il ne semble pas fonctionner. Voici le nouveau code jquery final:

$(document).ready(function() { 

// Check for hash value in URL 
var hash = window.location.hash.substr(1); 
var href = $('.nav li a').each(function(){ 

    var href = $(this).attr('href'); 
    if(hash==href.substr(0,href.length-5)){ 
     var toLoad = hash+'.php #content'; 
     $('#content').load(toLoad, function() { 
     $('#slideshow').innerfade({ 
     speed: 4500, 
     timeout: 6000, 
     type: 'sequence', 
     containerheight: '480px' 
     }); 
     }); 
    } 
}); 

$('.nav li a').click(function(){ 

var toLoad = $(this).attr('href')+' #content'; 
$('#content').hide('fast',loadContent); 


$('#load').remove(); 
$('#sub_corpo').append('<span id="load">sto caricando il contenuto...</span>'); 
$('#load').fadeIn('normal'); 
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5); 



function loadContent() { 
    $('#content').load(toLoad,'',showNewContent()) 

} 
function showNewContent() { 
    $('#content').show('normal',hideLoader()); 


} 
function hideLoader() { 
    $('#load').fadeOut('normal'); 
} 
return false; 

}); 

}); 

Juste pour vous donner plus d'infos, voici le code de la page qui doit être chargé via jquery dans la div "contenu":

<div id="content"> 
<div class="sub_corpo"> 
<div class="sub_sinistra"> 

<div id="slideshow"> 

<?php 

$args = array(
'post_type' => 'attachment', 
'numberposts' => -1, 
'post_mime_type' => 'image', 
'post_status' => null, 
'post_parent' => $post->ID 
); 
$images = get_posts($args); 
foreach($images as $image): 
echo wp_get_attachment_image($image->ID, 'full'); 
endforeach; ?></div> 



<h1>Lunarossa vini e passione</h1> 
<p> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<?php the_content(); ?> 
<?php endwhile; else: ?> 
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?> 
</p> 
</div> 
<div class="sub_destra"><img src="http://www.viniepassione.it/wp-content/uploads/2011/09/parco.jpg" alt="Monti Picentini" /> 
<h1>&nbsp;</h1> 
<p>I monti piacentini sono un gruppo montuoso dell'Appennino campano. I Monti picentini sono una terra il cui carattere morfologico &egrave; rimasto immutato nel tempo, cos&igrave; come le tipicit&agrave; gastronomiche, dalla nocciola Tonda di Giffoni al''olio delle colline salernitane ottenuto dalla spremitura dell'oliva Rotondella. Nel &quot;Parco regionale dei piacentini&quot; ricadono due oasi WWF, quella del monte Accellica e quella del Polveracchio. 
</p> 
</div> 
</div> 
</div> 

Merci pour votre temps et votre aide