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.
-
2Just don't call it in the first place?FluffyKitten– FluffyKitten2017-08-22 07:30:11 +00:00Commented Aug 22, 2017 at 7:30
-
You got the question wrong. You want to stop the scroll function working device specific. Try searching for such codes. It's easySagar– Sagar2017-08-22 07:34:50 +00:00Commented Aug 22, 2017 at 7:34
-
@FluffyKitten you don't understand my question i am not the one who worked on the project. i was just brought up after it was finished. and i don't know where it is being called.henok– henok2017-08-22 07:42:44 +00:00Commented Aug 22, 2017 at 7:42
-
1Wouldn't it be better to debug the project instead of disabling the function? It may or may not affect the project entirely.Sagar– Sagar2017-08-22 08:20:56 +00:00Commented Aug 22, 2017 at 8:20
-
I understand it can be difficult to maintain code that you have inherited, but trying to add a hack to like this is going to make it impossible to maintain in future. The existing code is written to perform a specific action and adding more code somewhere else to "block" those actions is a very bad idea - especially if you are preventing the default functionality of standard functions. You'll end up with code that no one knows what its doing and are more likely to introduce even more bugs.FluffyKitten– FluffyKitten2017-08-22 16:40:46 +00:00Commented Aug 22, 2017 at 16:40
Add a comment
|
4 Answers
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.
2 Comments
Tschallacka
you forgot to check yourself if
evt.defaultPrevented is true. Always check if evt.defaultPrevented has been called before.henok
there is no anchor tag here. the page just scrolls up when you scroll down