'How to disable a specific function in javascript?

I'm working on a Wordpress project and the site looks fine when viewed from desktop but on mobile it scrolls to top every time you try to scroll. so i want to know how to completely disable the scrollTop() jQuery function.



Solution 1:[1]

This works:

delete $.prototype.scrollTop

Solution 2:[2]

You can hook this function to customize its behavior

let originalScrollTop = window.scrollTop
function myScrollTop() {
  // Do something you like
  originalScrollTop() // you can decide whither call it or not
}

window.scrollTop = myScrollTop

Solution 3:[3]

You have to prevent default link click behaviour (which is: make a request of the resource defined by the href attribute value and load response) in your click event by doing this:

$("a").click(function(evt) {
    evt.preventDefault();
    // display your menu
    // and do what's required
});

Usually people also suggest to return false; from your handler, but that's not necessary. Still you can do that just before the closing curly brace of the click event handler function.

Solution 4:[4]

Best way is to locate the scrolling function and disable it manually (comment-out). Use CTRL+SHIFT+F in Chrome to search in page resources for scroll or scrollTop keywords and check javascript files.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Embri
Solution 2 L Baker
Solution 3 Mohhamad Hasham
Solution 4 Sergey Sklyar