此功能仅有效一次,当我再次单击锚元素时,不会发生任何事情。我认为选择器会将 .click 函数应用于所有匹配的元素?
$('#welcome-nav li a').click(function (e) {
// prevent anchor from firing
e.preventDefault();
var chosenElement = $(this).parent().attr('class');
var index = articles.indexOf('.' + chosenElement) + 1;
//remove all classes of active on articles
$.each(articles, function (index, value) {
$(value).removeClass('active');
})
$('.' + chosenElement).addClass('active');
$('#sharpContainer').bgStretcher.sliderDestroy();
startBgStretcher(returnImageArray(index));
})
下面是我认为破坏 onclick 功能的插件
$('#sharpContainer').bgStretcher({
images: imageContainer,
anchoring: 'left top', //Anchoring bgStrtcher area regarding window
anchoringImg: 'left top', //Anchoring images regarding window
nextSlideDelay: 8000, //Numeric value in milliseconds. The parameter sets delay until next slide should start.
slideShowSpeed: 2000, //Numeric value in milliseconds or(’fast’, ‘normal’, ’slow’). The parameter sets the speed of transition between images
transitionEffect: 'superSlide',
slideDirection: 'W',
callbackfunction: homepageSlide
});
function homepageSlide() {
//homepage slide is called after a slide has loaded
var index = $('li.bgs-current').index();
//hide current article
$.each(articles, function (index, value) {
$(value).removeClass('active');
})
//show next article
$(articles[index]).addClass('active');
}