Skip to content

Add onwheel #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2021
Merged

Conversation

vhiairrassary
Copy link
Contributor

Scala-js-dom currently supports onmousewheel but as written on MDN:

Do not use this wheel event. This interface is non-standard and deprecated. It was used in non-Gecko browsers only. Instead use the standard wheel event.

As mentioned above it is not supported on Firefox. This PR adds onwheel.

You can test with the following code:

import org.scalajs.dom
import org.scalajs.dom.html.Div

object Main {
  def main(args: Array[String]): Unit = {
    val onwheelChild = dom.document.createElement("div").asInstanceOf[Div]
    onwheelChild.textContent = "onwheelChild"
    onwheelChild.onwheel = event => {
      println("onwheel: " + event)
    }
    dom.document.body.appendChild(onwheelChild)
    
    val onmousewheelChild = dom.document.createElement("div").asInstanceOf[Div]
    onmousewheelChild.textContent = "onmousewheelChild"
    onmousewheelChild.onmousewheel = event => {
      println("onmousewheel: " + event)
    }
    dom.document.body.appendChild(onmousewheelChild)
  }
}

⚠️ MouseWheelEvent is different than the standard WheelEvent, and Scala-js-dom currently uses WheelEvent for the deprecated onmousewheel. I didn't want to change the Scala-js-dom code as it would break the compatibility for the current users. Note: on my computer, Chrome returns a WheelEvent for both events. Here is a screenshot showing the output of the above snippet:
Screenshot 2020-12-22 at 18 55 20

Also I didn't add documentation. Feel free to ask me to do it if required

@armanbilge armanbilge force-pushed the vhiairrassary/add-onwheel branch from 81dda21 to 5c241e5 Compare August 10, 2021 02:14
@armanbilge armanbilge changed the base branch from master to series/1.x August 10, 2021 02:14
@japgolly japgolly marked this pull request as draft August 12, 2021 23:54
@japgolly japgolly added this to the v1.2.0 milestone Aug 13, 2021
@japgolly japgolly marked this pull request as ready for review August 20, 2021 02:45
@japgolly japgolly merged commit 1215bd8 into scala-js:series/1.x Aug 20, 2021
@japgolly
Copy link
Contributor

Thanks for the PR and your patience @vhiairrassary!

@vhiairrassary vhiairrassary deleted the vhiairrassary/add-onwheel branch October 27, 2021 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants