国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

解決vue 界面在蘋果手機上滑動點擊事件等卡頓問題

2024-05-06 16:47:33
字體:
來源:轉載
供稿:網友

用vue編寫項目接近尾聲,需要集成到移動端中,在webstorm上界面,運行效果都很完美,但是在蘋果手機上各種問題都出現了,原生項目一向滑動流暢,事件響應迅速,可是蘋果手機打開這個項目有兩個問題,

(1).滑動頁面卡頓,

(2).點擊事件響應緩慢,百度才發現在蘋果手機上有300ms的延遲。

一.滑動頁面卡頓

//頁面布局<template> <div class='content'>  頁面內容 </div></template>

在對應的組件的最外層div上加上這樣的樣式:

.content{  -webkit-overflow-scrolling: touch;  }

-webkit-overflow-scrolling: touch;這句代碼最好可在公共的樣式中添加,防止很多頁面都需要寫的麻煩。這句代碼雖然可以解決滑動不流暢的問題,但是可能會引起幾個小問題:

(1).在滑動界面之中使用的position:fixed 無法固定下來,會隨著界面進行一起滾動

解決方法:將使用的position:fixed(頭部導航)寫在滑動部位外部,在使用絕對定位進行布局,以此解決問題

(2).vue中使用v-if導致的界面第一次無法滑動

解決方法:將v-if改成v-show進行展示,解決界面進入之后不能滑動的問題

二.點擊事件響應緩慢

(1).安裝fastclick (npm install fastclick -S)

(2).在main.js中設置方法

 

import FastClick from 'fastclick'FastClick.attach(document.body);

在引入fastclick之后,雖然頁面事件快了很多,但是會有一個副作用:input輸入框需要連續點擊兩次或者長按才能獲取焦點,真是到處是坑啊!

解決方法:在main.js中添加下面的代碼

FastClick.prototype.focus = function(targetElement) { var length;// Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. if (deviceIsIOS&& targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {  length = targetElement.value.length;  targetElement.focus();  targetElement.setSelectionRange(length, length); } else {  targetElement.focus();}};

總結

以上所述是小編給大家介紹的解決vue 界面在蘋果手機上滑動點擊事件等卡頓問題,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漳州市| 通渭县| 会理县| 巴青县| 靖安县| 文成县| 临江市| 兰考县| 伊金霍洛旗| 塔城市| 翁源县| 璧山县| 太白县| 肇庆市| 三明市| 河北区| 原阳县| 仁寿县| 永寿县| 呼伦贝尔市| 迭部县| 洛阳市| 若羌县| 栖霞市| 额尔古纳市| 达州市| 晋州市| 威海市| 常宁市| 平乐县| 化州市| 河南省| 大新县| 启东市| 菏泽市| 南涧| 当涂县| 瑞丽市| 磴口县| 上虞市| 和林格尔县|