您好我正在尝试在我的页面上使用以下代码....
http://codepen.io/jayeshvekariya/pen/jPjWEM
并且似乎无法让2个滑块脚本实例同时工作,我猜测答案是在js中的某个地方(或许添加一组辅助css类?)
var slideCount = document.querySelectorAll('.slider .slide-item').length;
var slideWidth = document.querySelectorAll('.slider-outer')[0].offsetWidth;
var slideHeight = document.querySelectorAll(".slider-outer")[0].offsetHeight;
var sliderUlWidth = slideCount * slideWidth;
document.querySelectorAll('.slider')[0].style.cssText = "width:" + sliderUlWidth + "px";
for (var i = 0; i < slideCount; i++) {
document.querySelectorAll('.slide-item')[i].style.cssText = "width:" + slideWidth + "px;height:" + slideHeight + "px";
}
setInterval(function() {
moveRight();
}, 3000);
var counter = 1;
function moveRight() {
var slideNum = counter++
if (slideNum < slideCount) {
var transformSize = slideWidth * slideNum;
document.querySelectorAll('.slider')[0].style.cssText =
"width:" + sliderUlWidth + "px; -webkit-transition:all 800ms ease; -webkit-transform:translate3d(-" + transformSize + "px, 0px, 0px);-moz-transition:all 800ms ease; -moz-transform:translate3d(-" + transformSize + "px, 0px, 0px);-o-transition:all 800ms ease; -o-transform:translate3d(-" + transformSize + "px, 0px, 0px);transition:all 800ms ease; transform:translate3d(-" + transformSize + "px, 0px, 0px)";
} else {
counter = 1;
document.querySelectorAll('.slider')[0].style.cssText = "width:" + sliderUlWidth + "px;-webkit-transition:all 800ms ease; -webkit-transform:translate3d(0px, 0px, 0px);-moz-transition:all 800ms ease; -moz-transform:translate3d(0px, 0px, 0px);-o-transition:all 800ms ease; -o-transform:translate3d(0px, 0px, 0px);transition:all 800ms ease; transform:translate3d(0px, 0px, 0px)";
}
}
如果有人能指出我正确的方向,那就太好了!