我接管了由别人构建的项目。该网站在主页上显示自定义幻灯片。我对每个客户端请求的幻灯片显示的外观/感觉进行了一些更改,但最后需要的是自动播放。需要帮助让自定义幻灯片自动播放
下面是幻灯片的脚本。我知道setInterval
,但我不知道放在哪里,或者如果需要的代码下降,在之前调整了一下。
$(document).ready(function() {
// A little script for preloading all of the images
// It"s not necessary, but generally a good idea
$(images).each(function(index, value){
// Ski first image since it is already loaded
if(index != 0) {
$("<img/>")[0].src = this;
}
});
// Feature Slider Navagitaion
$('.feature .ei-slider-nav li a').click(function(e) {
e.preventDefault();
var thisLink = $(this);
var navIndex = thisLink.parent('li').index();
thisLink.parents('ul').children('li').removeClass('active');
thisLink.parent('li').addClass('active');
// Is this item already active?
if(!$('.feature .ei-slider-title .ei-slider-title-item:eq('+navIndex+')').hasClass('active')) {
// Fade in/out feature image
$('.feature .ei-slider-large img').animate({opacity: 0}, 500, function() {
// Support for non-opacity browsers
$(this).css('visibility', 'hidden');
// Load new feature image
$(this).attr('src', images[navIndex]);
$(this).attr('alt', imagesAlt[navIndex]);
$(this).css('visibility', 'visible');
$('.feature .ei-slider-large img').animate({opacity: 1}, 500);
});
// Fade in/out feature text
$('.feature .ei-slider-title .ei-slider-title-item.active').fadeOut(500, function() {
$(this).parent().children().removeClass('active');
$('.feature .ei-slider-title .ei-slider-title-item:eq('+navIndex+')').addClass('active').fadeIn();
});
// Fade in/out feature credit
$('.content .ei-slider-credit span.active').fadeOut(500, function() {
$(this).parent().children().removeClass('active');
$('.content .ei-slider-credit span:eq('+navIndex+')').addClass('active').fadeIn();
});
}
});
// Feature Slider Learn More
$('.feature .ei-slider-title-item-learn').click(function(e) {
e.preventDefault();
thisPrev = $(this).prev();
if(thisPrev.css('display') == 'none') {
thisPrev.slideDown();
thisPrev.css('visibility', 'visible');
thisPrev.animate({'opacity': 1}, 500, function() {
});
$(this).html('Hide');
} else {
thisPrev.animate({'opacity': 0}, 500, function() {
thisPrev.slideUp();
thisPrev.css('visibility', 'hidden');
});
$(this).html('Hide');
$(this).html('Learn More');
}
});
});
谢谢!
感谢埃文。我查看了它并应用了更改,但它不起作用。据我所知,eiSlider是可用的,但为了防万一,我改变了它,但仍然没有。在控制台中也没有错误。滑块仍然像以前一样工作,只是附加的自动播放代码不起作用。这里总共noob。 :) – 2015-04-14 18:47:58
嘿安吉 - 原代码中有一些错误。我修复了这些问题并进行了一些额外的增强。自动播放功能现在应该可以工作了,如果您查看了JS Bin I链接,您可以看到如何在用户单击幻灯片的导航链接时禁用自动播放功能。 – 2015-04-14 19:34:47
这样做,谢谢! – 2015-04-14 19:41:35