Skip to content

JavaScript delta

deltaMode

The JavaScript deltaMode property returns a number that represents the unit of the shift values.

  • 0 = pixels
  • 1 = lines
  • 2 = pages

Syntax:

var deltaMode = event.deltaMode

  • This property is read-only.

Example

deltaMode example
<body onwheel="deltaFunction(event)">

    <p id="result"></p>
    <p><strong>Note:</strong> 0 = pixels, 1 = lines, 2 = pages.</p>

    <script>

        function deltaFunction(event) {
            var dlt = event.deltaMode;
            document.getElementById("result").innerHTML = dlt;
        }

    </script>
</body>

deltaX

The JavaScript deltaX property returns numbers that are scrolled to the right and left. Moving to the right takes positive values. If we slide to the left, it takes negative values. Returns 0 if no scrolls.

Notes:

  • Most mouse devices do not have the ability to scroll left and right and always return 0.
  • This property is read-only.

Syntax:

var deltaX = event.deltaX;

  • This property is read-only.

Example

deltaX example
<body onwheel="deltaFunction(event)">

    <h2>deltaX</h2>
    <p id="result"></p>
    <p><strong>Note:</strong> 0 = pixels, 1 = lines, 2 = pages.</p>

    <script>

        function deltaFunction(event) {
            var dlt = event.deltaX;
            document.getElementById("result").innerHTML = dlt;
        }

    </script>
</body>

deltaY

The JavaScript deltaY property returns numbers that are scrolled up and down. Gets negative values ​​when scrolling upwards. Gets positive values ​​slid down. Returns 0 as the default value if it is not wrapped.

Syntax:

var deltaY = event.deltaY;

  • This property is read-only.

Example

deltaY example
<body onwheel="deltaFunction(event)">

    <h2>deltaY</h2>
    <p id="result"></p>
    <p><strong>Note:</strong> 0 = pixels, 1 = lines, 2 = pages.</p>

    <script>

        function deltaFunction(event) {
            var dlt = event.deltaY;
            document.getElementById("result").innerHTML = dlt;
        }

    </script>
</body>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: