I have a page with some checkboxes items and then a textarea
element at very bottom of the page. This textarea
has no autofocus assigned.
<textarea id="comments" class="form-control" rows="8">@Comments</textarea>
textarea
always get focus when page loads and scroll to bottom itself.
It has to be working for Android and iPhone webview containers.
I have tried a lot to scroll to top after page loads or remove the focus from this element but no luck so far.
I have tried below different tricks I found here:
$("html,body").animate({ scrollTop: 0 }, "slow");
$(this).scrollTop(0);
$('textarea').blur();
$('#comments').blur();
document.activeElement.blur();
document.getElementById("origin").focus();
$('html,body').animate({
scrollTop: $("#origin").offset().top
});
$("body").scrollTop(0);
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
even button go to top click not working
$("#myBtn").on("click", function () {
console.log('ddd');
$(this).scrollTop(0);
$("html").scrollTop(0);
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
});
I also found it could be because of overflow: scroll on main container which could preventing scrolltotop
from working.
so here is my main container details from _Layout.chtml page.
#mobile-content-wrapper {
position: relative;
width: 100%;
padding-bottom: 80px;
overflow-y: scroll;
overflow-x: hidden;
I could use some of your experience here.