Ich habe eine kleine Diashow gemacht und ich versuche es zu automatisieren. HTML-Elemente sind wie folgt aus:Jquery Machen Sie eine Diashow automatisch
<ul>
<li>
<h3 class="active-item" data-bg="background-image url">Title 1</h3>
<div class="news-excerpt"><p>The excerpt</p></div>
</li>
<li>
<h3 class="" data-bg="background-image url">Title 2</h3>
<div class="news-excerpt"><p>The excerpt</p></div>
</li>
<li>
<h3 class="" data-bg="background-image url">Title 3</h3>
<div class="news-excerpt"><p>The excerpt</p></div>
</li>
</ul>
Hier ist meine Diashow:
$("#alternative-navigation div#last-posts-fadeshow h3").click(function(){
// Get url of the background image to show.
var bgvar = $(this).attr("data-bg");
// Set the right post excerpt to show
$('.active-excerpt').removeClass('active-excerpt');
$(this).next('.news-excerpt').addClass('active-excerpt');
$('.active-item').removeClass('active-item');
$(this).addClass('active-item');
Cufon.refresh();
//alert (bgvar);
// Switch to right background image
$("#background-image-container").fadeTo('medium', 0.1, function()
{
$("#background-image-container").css("background-image", "url(" + bgvar + ")");
}).fadeTo('medium', 1);
return false;
});
Jetzt möchte ich es automatisch alle 4 Sekunden ablaufen. Wie könnte ich das funktionieren lassen:
$('html').addClass('js');
$(function() {
var timer = setInterval(showDiv, 3000);
function showDiv() {
// Select the next post to show
$(this) = $('#alternative-navigation div#last-posts-fadeshow h3.active-item').parent().next().find('h3');
// Get url of the background image to show.
var bgvar = $(this).attr("data-bg");
// Set the right post excerpt to show
$('.active-excerpt').removeClass('active-excerpt');
$(this).next('.news-excerpt').addClass('active-excerpt');
$('.active-item').removeClass('active-item');
$(this).addClass('active-item');
Cufon.refresh();
//alert (bgvar);
// Switch to right background image
$("#background-image-container").fadeTo('medium', 0.1, function()
{
$("#background-image-container").css("background-image", "url(" + bgvar + ")");
}).fadeTo('medium', 1);
return false;
}
});
Der erste Teil scheint den richtigen Titel auszuwählen, aber nichts passiert. Irgendwelche Ideen?
Danke, ich habe etwas gelernt :), das hat funktioniert. Hast du eine Idee, wie ich den ersten Gegenstand auswählen kann, wenn die Funktion den letzten Gegenstand erreicht? – Joeyjoejoe
Ich habe Code hinzugefügt, der Sie in die richtige Richtung zeigen sollte :) –
Vielen Dank, es funktioniert gut mit diesem Selektor "nextitem = $ ('# alternative-navigation div # letzte-posts-einblenden ul li: first-child') .find ('h3'); " – Joeyjoejoe