javascript - 为什么 touch 方法不能接收到 className 的参数?
问题描述
由于我发现它在传递函数时new className(param)
并不直接引用 an ,因此我一直在尝试将 HTML 类传递给而不更改。但它不断检测.instance(param){}
constructor
instance method
param
这是我的代码:
class Slider {
'use strict';
istouchStart(e) {
console.log(e.target);
this.coordX = e.touches[0].clientX;
return this.coordX;
}
constructor(target) {
// Variables
var _ = this;
console.log(target);
$(target).stop(true, true).on({
touchstart:_.istouchStart,
touchmove:_.istouchMove,
touchend:_.istouchEnd
});
}
}
const image = new Slider('.inline-grid');
div {
position: relative;
}
.inline-grid {
margin: 0 auto;
width: 2560px;
border: 1px solid black;
display: flex;
flex-flow: row;
overflow: hidden;
}
.wrap {
width: 100%;
display: flex;
flex-flow: row;
}
.cell {
display: flex;
flex-flow: column;
flex-shrink: 0;
width: 100%;
height: 200px;
}
.orange {
background-color: orange;
}
<div class="inline-grid">
<div class="wrap">
<div class="cell orange"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
我将如何.inline-grid
从该istouchStart
方法中获得?
这是使用return
和箭头函数的第二次尝试,但是这个函数在没有显示错误的情况下不起作用。:
static istouchStart() {
return (e) => {
console.log(e.target);
this.coordX = e.touches[0].clientX;
}
}
解决方案
推荐阅读
- python - 为什么与 MSE 相比,使用 MAE 标准训练随机森林回归器如此缓慢?
- bash - Bash 脚本不执行指令
- .net-core - UWP:访问冲突仅在发布模式下发生
- java - 需要一种为 Spring Boot 生成 Java 类的方法
- sql - 一段时间内的总销售额
- python - 无法使用python从列表元素中删除双引号
- python - 如何在没有硒的情况下使用 python 读取 chrome 控制台?
- java - 什么可能导致计时器在 RecyclerView 中闪烁?
- python-3.x - 是否可以在 __name__ == '__main__' 块中获取要执行的脚本的内容(其文件名或内容)?
- python - 为什么建议不要在 conda 基础环境中安装额外的包?它的目的是什么?