question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to enable the ability to scroll a page with Matter.js?

See original GitHub issue

I want to enable scrolling in a page that contains a Matter.js canvas. I have found and tried a few solutions such as removingEventListener without success. I created a post on StackOverflow but no luck with answers. Therefore I decided to come directly to the source of knowledge.

How can I enable page scrolling in a page with Matter.js? Thank you in advance.

Here’s the Codepen and the post.

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
bouraqadicommented, Nov 1, 2020

The answer is provided by Xander Gottlieb in a blog post along with many other tips Matter.js— The Missing Tutorial.

By default, MouseConstraint captures scroll events. The following snippet fixes it.

mouseConstraint.mouse.element.removeEventListener("mousewheel", mouseConstraint.mouse.mousewheel);
mouseConstraint.mouse.element.removeEventListener("DOMMouseScroll", mouseConstraint.mouse.mousewheel);
3reactions
ayank007commented, Jun 14, 2022

I’m still unable to solve the problem in touch screen devices.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent scroll on bodies (Matter.js) - javascript - Stack Overflow
This makes it possible for the user to scroll through the page and still being able to interact with the scene by clicking...
Read more >
Physics-Based Background Scroll Effects - Coder's Block
This article will show you how to create nifty physics-based background scroll effects for your web pages. We'll be using Matter.js, ...
Read more >
1 How to load matter.js into p5 web editor p5.js - YouTube
Learn 2 ways to load matter. js into the p5 web editor:#1. Download matter. js & upload it into the p5 web editor#2....
Read more >
Getting Started With Matter.js: The Body Module - Code
In this tutorial, you will learn about all these methods and properties and how to use them properly. Scaling, Rotating, and Translating a...
Read more >
How to get started with matter.js and Physics in JavaScript
If you want you can check some of the demo's. On the sidebar, click 'Source Code' which should lead you to the GitHub...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found