jquery on scroll element code example

Example 1: jquery on wheel event

$("#main-div" ).on( 'wheel', function() {
   alert("Hello! I am an alert box!!");
});

Example 2: jquery on scroll

Syntax
Trigger the scroll event for the selected elements:
$(selector).scroll()

Attach a function to the scroll event:
$(selector).scroll(function)

Example 3: angular scroll event on div chang width

<body style="overflow: scroll; height: 1000px;" onload="scrollDetect()">
    <div class="firstdiv" style="border:1px solid black; margin: 0 auto; width: 200px;height: 200px;">
    </div>

    <script>
        function scrollDetect() {
            let div = document.querySelector('.firstdiv')
            var lastScroll = 0;
            window.onscroll = function () {
                let currentScroll = document.documentElement.scrollTop; // Get Current Scroll Value
                if (currentScroll > 0 && lastScroll <= currentScroll) {
                    lastScroll = currentScroll;
                    div.style.width = '50%'
                    div.style.height = "50%";
                    div.style.background = "red";
                    div.style.position = "relative";
                    div.style.top = "0";
                    div.style.left = "0";
                } else {
                    lastScroll = currentScroll;
                    div.style.width = '200px'
                    div.style.height = '200px'
                }
            };
        }
    </script>
</body>