1. 程式人生 > 其它 >解決移動端H5頁面軟鍵盤彈起input失焦後不回彈底部

解決移動端H5頁面軟鍵盤彈起input失焦後不回彈底部

技術標籤:vue.jsjavascript

**給input新增@blur失去焦點事件**
	<view class="label iconfont iconlock">
	<input type="text" placeholder="真實姓名" placeholder-class="place" v-model="formData.realName" @blur.prevent="inputLoseFocus"/>
	</view>
**解決方法函式**
inputLoseFocus() {
	let currentPosition, timer;
	let speed = 1; //頁面滾動距離
	timer = setInterval(function() {
	currentPosition = document.documentElement.scrollTop || document.body.scrollTop;
	currentPosition -= speed;
	window.scrollTo(0, currentPosition); //頁面向上滾動
	currentPosition += speed;
	window.
scrollTo(0, currentPosition); //頁面向下滾動 clearInterval(timer); }, 1); },