Why is the condition triggered?

  • 0
    $(window).scroll(function () {
    	if ($(this).scrollTop() == 0 ){
    		window.onwheel = function(event) {
    			if (event.deltaY < 0) {
    			} else {

    I don't understand how it works, how can the code console.log ('222222222'); fire and the code console.log ('1111111111'); no? According to my logic, console.log ('222222222') should only fire if $ (this) .scrollTop () == 0, that is, scroll to the top of the screen.
    Scroll the wheel down a bit, then up again to the end, then to the very bottom of the entire site and do it back and forth, 222222222 appears in the console without 1111111111. Why is this happening?
    If you print $ (this) .scrollTop (), then it will not equal 0, which, in principle, is already clear.
    JavaScript Emmett Pratt, Feb 25, 2020

  • 1 Answers
  • 0
    I have not learned JS, but I am learning C # and I still see an error, take a closer look at your code), a little tip "why the second check if there is a first one)?"

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!