我正在使用JavaScript中的可触摸图像滑块,然后打开控制台(单击“检查器”后),看到此错误:
SyntaxError: missing ) after argument list
这是用PUG编写的文件的全部代码,我认为这是出问题的了:
doctype html
html
head
meta(
name="viewport",
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalabel=no",
)
style.
body {
overflow: hidden;
}
.image {
height: 100vh;
width: 100vw;
}
.image-list {
display: flex;
flex-wrap: nowrap;
position: absolute;
left: -170%;
}
head,
body {
height: 100%;
}
body
.image-list
each image in ['lavender', 'lavenderblush', 'pink']
.image(style=`background-color:${image}`)=image
script.
const imageElementList =
[... document.querySelectorAll('.image')];
imageElementList.map(imageElement => {
const imageElementDimensions =
imageElement.getBoundingClientRect();
const windowWidth = window.screen.width;
let start = 0,
end = 0;
imageElement.addEventListener('touchstart', e
=> {
start = e.touches[0].clientX;
console.log(start)
})
imageElement.addEventListener('touchend', e => {
end = e.changedTouches[0].clientX;
console.log(end)
const direction = start - end;
if(direction > 0) {
console.log('left',
imageElementDimensions.left,
windowWidth)
//- Decrease the left style property
imageElement.style.left = (imageElementDimensions.left - windowWidth) + 'px';
} else {
console.log('right')
}
})
})
以下是YouTube上视频的链接,您可以看到结果如何:https://www.youtube.com/watch?v=tm_vSJFMqwA&list=PLlgRhtOkjmmDaca6lcyJ2DYh6GNAXzrto&index=4
有人可以帮忙吗?谢谢。
答案 0 :(得分:0)
问题是我在.image-list
中输入了left: -170%;
,这是我不想要的。我重新观看了YouTube视频,在添加了教程中提到的一些代码后,它仍然可以正常工作。