我正在使用一个圆滑的旋转木马,我希望非活动幻灯片在opacity .4上...因此,我创建了一个变量数组(变量引用幻灯片的类)和一个for循环,用于在单击X类时迭代.click() jQuery函数的变量,在所有其他类上迭代.css不透明.4的变量。在单击时,只有一个类(另一个幻灯片图像)会淡入淡出,所以我循环遍历数组并对数组和数组进行console.logged。令我惊讶的是,当console.logging数组时,它记录了包含类和内联样式更改的html。当我通过控制台记录阵列时,它记录了div.test__image.explosiveness。我的循环出了什么问题/我如何才能针对css更改的所有索引?我使用PUG的超文本标记语言和JS/ jQuery。提前感谢您的帮助和建议!
.carousel
.carousel__slide
.test
.test__image.explosiveness
p Explosiveness
.carousel__slide
.test
.test__image.agility
p Agility
.carousel__slide
.test
.test__image.flexibility
p Flexibility
.carousel__slide
.test
.test__image.balance
p Balance
.carousel__slide
.test
.test__image.footwork
p Footwork
.carousel__slide
.test
.test__image
p Explosiveness// carousel fades
var agility = document.getElementsByClassName('agility'),
explosiveness = document.getElementsByClassName('explosiveness'),
flexibility = document.getElementsByClassName('flexibility'),
balance = document.getElementsByClassName('balance'),
footwork = document.getElementsByClassName('footwork');
var nonFootwork = (agility, balance, flexibility, explosiveness);
$('.footwork').click(function(){
var len = nonFootwork.length;
for(var i = 0; i < len; i++){
$(nonFootwork[i]).css('opacity', '.4');
console.log(nonFootwork[i]);
console.log(nonFootwork);
$('.footwork').css('opacity', '1');
}
});发布于 2017-07-19 02:14:59
您应该使用括号而不是括号来声明数组:
var nonFootwork = [agility, balance, flexibility, explosiveness];https://stackoverflow.com/questions/45174209
复制相似问题