JQuery addClass window scrolls back to top on Android and iPhone

I am working on a page where an element sits below, which is activated by clicking on it. Then the element expands (instantly) in height to show its contents. This is done by adding a class (".active") with jQuery to this element.

All active. Active adds - this is a display unit and some height. However, every time you click on it, the browser jumps back. If I comment on the addClass part in javascript, it will behave normally.

For heads up only, the anchor tag does not have "href = #".

+6
source share
1 answer

As a temporary fix, you can put the screen in position each time you press.

$('.troublemaker').click(function(e){ var currentScroll = $(document).scrollTop(); setTimeout( function(){ $(document).scrollTop( currentScroll ); }, 10 ); }); 
0
source

Source: https://habr.com/ru/post/910070/


All Articles