0
我做了一个幻灯片放映,我试图自动化它。 HTML元素是这样的:Jquery自动幻灯片放映
<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>
这里是我的幻灯片:
$("#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;
});
现在,我希望它每4秒automaticaly进行。我怎么能有这样的工作:
$('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;
}
});
第一部分似乎选择合适的标题,但没有发生。有任何想法吗?
谢谢,我学到了东西:),这工作。你有一个想法,关于当功能到达最后一个项目时如何选择第一个项目? – Joeyjoejoe 2012-04-11 10:14:39
我添加了一些代码,应该指出你在正确的方向:) – 2012-04-11 10:19:06
非常感谢,它适用于该选择器“nextitem = $('#alternative-navigation div#last-posts-fadeshow ul li:first-child' ).find( 'H3');” – Joeyjoejoe 2012-04-11 10:46:26