Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Matter.js—;如何防止mouseConstraint捕获滚动事件?_Javascript_Mouseevent_Matter.js - Fatal编程技术网

Javascript Matter.js—;如何防止mouseConstraint捕获滚动事件?

Javascript Matter.js—;如何防止mouseConstraint捕获滚动事件?,javascript,mouseevent,matter.js,Javascript,Mouseevent,Matter.js,我正在尝试启用滚动到包含Matter.js画布的页面。我到处查看,建议添加removeEventListener,这样鼠标约束就不会劫持滚动事件。不幸的是,我没有成功。如何启用滚动 提前谢谢你 代码 这是一个HTML问题。在index.html中,将溢出设置为滚动Nootrix,您就是赢家。谢谢你的提醒。 import "./styles.css"; import Matter from "matter-js"; //Fetch our canvas

我正在尝试启用滚动到包含Matter.js画布的页面。我到处查看,建议添加
removeEventListener
,这样鼠标约束就不会劫持滚动事件。不幸的是,我没有成功。如何启用滚动

提前谢谢你

代码


这是一个HTML问题。在index.html中,将
溢出
设置为
滚动

Nootrix,您就是赢家。谢谢你的提醒。
import "./styles.css";
import Matter from "matter-js";

//Fetch our canvas
var canvas = document.getElementById("world");

//Setup Matter JS
var engine = Matter.Engine.create();
var world = engine.world;
var render = Matter.Render.create({
  canvas: canvas,
  engine: engine,
  options: {
    width: 500,
    height: 500,
    background: "transparent",
    wireframes: false,
    showAngleIndicator: false
  }
});

//Add a ball
var ball = Matter.Bodies.circle(250, 250, 50, {
  density: 0.04,
  friction: 0.01,
  frictionAir: 0.00001,
  restitution: 0.8,
  render: {
    fillStyle: "#F35e66",
    strokeStyle: "black",
    lineWidth: 1
  }
});
Matter.World.add(world, ball);

//Add a floor
var floor = Matter.Bodies.rectangle(250, 520, 500, 40, {
  isStatic: true, //An immovable object
  render: {
    visible: false
  }
});
Matter.World.add(world, floor);

//Make interactive
var mouseConstraint = Matter.MouseConstraint.create(engine, {
  //Create Constraint
  element: canvas,
  constraint: {
    render: {
      visible: false
    },
    stiffness: 0.8
  }
});
Matter.World.add(world, mouseConstraint);

// Why is this not working?
mouseConstraint.mouse.element.removeEventListener(
  "mousewheel",
  mouseConstraint.mouse.mousewheel
);
mouseConstraint.mouse.element.removeEventListener(
  "DOMMouseScroll",
  mouseConstraint.mouse.mousewheel
);

//Start the engine
Matter.Engine.run(engine);
Matter.Render.run(render);