作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否有人知道如何使用 Matter.js 实现悬停效果.我已经检查了他们的文档,但无法弄清楚。虽然,有鼠标 - mousedown、mouseup、mousemove 和 more .
我已经研究过,但找不到任何有用的信息。我知道形状/物理是在 Canvas 内呈现的。任何信息或建议都会非常有帮助。
最佳答案
我想出了实现悬停行为的方法。为此,我使用了 Matter.Query.point 和“mousemove”(Matter.Events.on) 方法。感谢@philipp上面为我指出了正确的方向。这是简单的代码。
//Need to add MouseConstraint for mouse events
var mConstraint;
mConstraint = MouseConstraint.create(engine, options);
Matter.World.add(world, mConstraint);
//Add event with 'mousemove'
Matter.Events.on(mConstraint, 'mousemove', function (event) {
//For Matter.Query.point pass "array of bodies" and "mouse position"
var foundPhysics = Matter.Query.point(bodies, event.mouse.position);
//Your custom code here
console.log(foundPhysics[0]); //returns a shape corrisponding to the mouse position
});
编码愉快! :)
关于javascript - 如何在 Matter.js 中实现鼠标悬停行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55257829/
我是一名优秀的程序员,十分优秀!