【发布时间】:2019-04-30 14:47:37
【问题描述】:
您好,我正在尝试模拟滑块中的箭头,我将元素向左和向右移动。
到目前为止,我的项目向右移动了一次。
https://i.gyazo.com/34a0ef4a5064c2942aca7c717a775e8b.mp4
这是我目前的代码
<script>
(function(){
const arrowLeft = document.querySelector('#video-tags-left');
const arrowRight = document.querySelector('#video-tags-right');
const tags = document.querySelector('.video-tags');
const now = "740";
arrowRight.addEventListener("click", function() {
$(tags).css({
"transform": "translate3d(" + -now + "px, 0px, 0px)",
"transform-style": "preserve-3d"
});
});
arrowLeft.addEventListener("click", function() {
$(tags).css({
"transform": "translate3d("+ +now+", 0px, 0px)",
"transform-style": "preserve-3d"
});
});
}());
</script>
所以我尝试添加和删除now,点击时为 740,所以每次点击右时添加 740,点击左时删除,直到重置为 0px。
因此,当用户单击左箭头时,我再次单击 740 再次 1460 等,反之亦然。
【问题讨论】:
标签: javascript jquery translate3d