所以我正在尝试求解一个涉及鼠标点击/触摸 Action 和移动交互的方程式。工作起来很像 slider ,但它会使动画逐帧运行,这就是为什么我只需要数字。
<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;
};
有人能救救我吗?
最佳答案
使用 Number.parseInt
。来源:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt
关于javascript - 从 offsetX 值中获取数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53733058/