問題描述:H5頁面在微信中打開,input輸入框獲取焦點時,頁面被軟鍵盤頂上去;關閉軟鍵盤時,頁面不會自動下來(恢復初始狀態)微信
H5頁面在微信中初始狀態以下圖:.net
input輸入框獲取焦點時,頁面被軟鍵盤頂上去,以下圖:blog
關閉軟鍵盤時,頁面沒有自動落下,以下圖:input
解決方法:
方法一:io
$(input).on('blur',function(){
window.scroll(0,0);
});function
scroll 註解:scroll(x,y),x表示水平滾動條位置,y表示垂直滾動條位置select
方法二:scroll
$("input").on(‘blur’,function(){
$(window).scrollTop(0);
});方法
scrollTop 註解:元素滾動條的垂直位置im
順帶寫幾個其餘的:
scrollLeft(number); 元素滾動條的水平位置
$(selector).scrollTop(offset) offset: 可選。規定相對滾動條頂部的偏移,以像素計。
---------------------
轉載 :黑夜世界 原文:https://blog.csdn.net/amy_king_0/article/details/86612901