javascript - 从 offsetX 值中获取数值
问题描述
所以我试图解决一个涉及鼠标点击/触摸动作和移动交互的方程。工作起来很像一个滑块,但它会让动画逐帧运行,这就是我只需要数字的原因。
<html>
<header>
<!-- By the way, this is not the actual html file, just a generic example. -->
<style>
#box{
border:1px solid red;
height:500px;
width:500px;
}
</style>
</header>
<body>
<div id="box" onclick="posInicial()" onmousemove="posMove()"></div>
<div id="Z" ></div>
<script>
function posInicial() {
var posX = event.offsetX;
return posX;
};
function posMove() {
var posY = event.offsetX;
return posY;
};
var z = posY - posX;
document.getElementById("Z").innerHTML = z;
</script>
</body>
</html>
每当我编写下面的代码时,我都可以在 HTML 中实时显示和更新数字,但我需要动画帧控件的“减号”操作中的实际值
function posInicial() {
var posX = event.offsetX;
document.getElementById("Z").innerHTML = posX;
};
有人可以救我吗?
解决方案
推荐阅读
- angular - 多个输入字段的角度值
- java - 使用 JSOUP 通过 URL 解析整个 html(平均大小 20MB)
- python - 如何使用 -v 标志运行 Python 的 unittest.TestSuite()?
- javascript - 使用 bcrypt 和对象分配的密码散列
- excel - Excel 宏,运行一次且永不重复,通过 XLAM 分发
- airflow - 如何确保在任何给定时间只有一个操作员实例(用于多个 dags)在 Airflow 中运行?
- c# - 如何以 xamarin 形式获取电话号码?
- html - 如何使用 ngModel 未更改的表单组件的值?
- r - 如何将包含 2019 年日期的列添加到数据集中?
- matlab - heaviside 命令对于离散时间信号和系统是否有效/合法?