jquery - 启用触摸屏控制
问题描述
美好的日子,快乐的人们。
我有这个由网络上的教程/代码片段制作的分屏滑块的java代码:
var Lslide = document.querySelectorAll('.Lslide'),
Rslide = document.querySelectorAll('.Rslide'),
control = document.querySelectorAll('.oncontrol'),
slideHeight = document.querySelector('.wrapper').clientHeight,
color = ['#fdc97c', '#e5d3d0', '#71b3d6'],
index = 0;
function init() {
slideHeight = document.querySelector('.wrapper').clientHeight;
for (i = 0; i < Lslide.length; i++) {
Lslide[i].style.backgroundColor = color[i];
Lslide[i].style.top = -slideHeight * i + "px";
Rslide[i].style.top = slideHeight * i + "px";
}
}
init()
window.addEventListener('resize', function(){
init()
});
function moveToTop() {
index++;
for (el = 0; el < Lslide.length; el++) {
Lslide[el].style.top = parseInt(Lslide[el].style.top) + slideHeight + "px";
Rslide[el].style.top = parseInt(Rslide[el].style.top) - slideHeight + "px";
}
if (index > Lslide.length-1) {
index = 0;
for (el = 0; el < Lslide.length; el++) {
Lslide[el].style.top = -slideHeight * el + "px";
Rslide[el].style.top = slideHeight * el + "px";
}
}
}
function moveToBottom() {
index--;
for (el = 0; el < Lslide.length; el++) {
Lslide[el].style.top = parseInt(Lslide[el].style.top) - slideHeight + "px";
Rslide[el].style.top = parseInt(Rslide[el].style.top) + slideHeight + "px";
}
if (index < 0) {
index = Rslide.length-1;
for (el = 0; el < Lslide.length; el++) {
Lslide[el].style.top = parseInt(Lslide[el].style.top) + slideHeight * Lslide.length + "px";
Rslide[el].style.top = parseInt(Rslide[el].style.top) - slideHeight * Rslide.length + "px";
}
}
}
function transition() {
for (t = 0; t < Lslide.length; t++) {
Lslide[t].style.transition = "all 0.8s";
Rslide[t].style.transition = "all 0.8s";
}
}
for (t = 0; t < control.length; t++) {
control[t].addEventListener("click", function() {
if (this.classList.contains('control-top')) {
moveToTop()
}
if (this.classList.contains('control-bottom')) {
moveToBottom()
}
transition()
});
}
var wheeling;
function mousemouve(e) {
clearTimeout(wheeling);
e.preventDefault();
var e = window.event || e;
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
wheeling = setTimeout(function() {
wheeling = undefined;
if (delta === 1) {
moveToTop()
}
if (delta === -1) {
moveToBottom()
}
}, 100);
transition()
}
document.addEventListener("mousewheel", mousemouve);
document.addEventListener("DOMMouseScroll", mousemouve);
如何为支持触控的设备的幻灯片启用触控?另外,如何为屏幕宽度小于 460 像素的设备添加不同类型的过渡?
非常感谢您的宝贵时间。
解决方案
推荐阅读
- git - 从 git LFS 中提取所有文件
- javascript - 从外部返回一个 Promise 的值
- ios - 为什么动画不起作用但打印语句起作用?
- python - PyMySQL 访问被拒绝“使用密码(否”)但使用密码
- html - 我的第二个字体怎么没有加载?
- swift - 对 XLPagerTabStrip 控制器中的所有视图控制器使用一个选项卡
- php - 在 Laravel 5.5 中实现 Mail 时出现此错误---->Missing argument 1 for Illuminate\Support\Manager::createDriver()
- loops - 在循环中更改顺序椭圆的颜色
- android - 使用 Management API 启动应用程序
- java - Eclipse 不显示多种方法的输出?