Vue implements the shake function (compatible with ios13.3 and above)

Vue implements the shake function (compatible with ios13.3 and above)

Recently, I made a function similar to shake, using shake.js. However, the shake function can be triggered in versions before ios13.3, and later versions need to be compatible. It is necessary to create a pop-up box that users can click manually so that users can authorize permissions for actions and directions. (https protocol is required)

<van-popup v-model="isTip" class="popInfo" :close-on-click-overlay="false">
 <div class="mainBody">
 <h3 class="systemTip">Warm Tips</h3>
 <div class="confirm">
 Since the iOS system needs to manually obtain permission to access actions and directions, to ensure the normal progress of the game, please click Allow in the access prompt.
 </div>
 </div>
 <button class="bottomButton" @click="handleInit">
 Got it</button>
</van-popup>

shake.js

//Introduce shake.js
created(){
 this.initShake()
 const isAction = JSON.parse(localStorage.getItem('getAction'))
 var ua = navigator.userAgent.toLowerCase();
 if (ua.indexOf("like mac os x") > 0) {
 var reg = /os [\d._]*/gi ;
 var verinfo = ua.match(reg);
 var version = (verinfo+"").replace(/[^0-9|_.]/ig,"").replace(/_/ig,".");
 if (parseFloat(version) >= 13.3 && !isAction){
 localStorage.setItem("getAction",true)
 this.isTip = true
 }
 }
},
methods:{
 initShake(){
 this.myShakeEvent = new Shake({
 threshold: 15, // shake threshold timeout: 1000 // event frequency, optional value});
 this.myShakeEvent.start();
 window.addEventListener('shake', xx);
 },
 handleInit(){
 this.isTip = false
 this.ios13granted()
 },
 ios13granted() {
 if (typeof DeviceMotionEvent.requestPermission === 'function') {
 DeviceMotionEvent.requestPermission().then(permissionState => {
 if (permissionState === 'granted') {
 this.initShake() //Shake} else if(permissionState === 'denied'){// The link you opened does not begin with https alert("The current IOS system denies access to actions and directions. Please exit WeChat and re-enter the event page to obtain permissions. Or directly click on the lottery bucket to participate in the event")
 }
 }).catch((error) => {
 alert("Requesting device orientation or motion access requires user gestures to prompt")
 })
 } else {
 // Handle regular non-iOS 13+ device alert("Handle regular non-iOS 13+ devices")
 }
 },
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • JavaScript+H5 to implement WeChat shake function
  • Analysis of the principle of WeChat shake using JS
  • Implementation of the shake function in javascript html5

<<:  Detailed explanation of nginx optimization in high concurrency scenarios

>>:  What to do if you forget the initial password of MySQL on MAC

Recommend

Detailed explanation of Vue's caching method example

Recently, a new requirement "front-end cache...

How to let DOSBox automatically execute commands after startup

Using DOSBox, you can simulate DOS under Windows ...

Util module in node.js tutorial example detailed explanation

Table of contents Starting from type judgment Str...

Solve the problem of OpenLayers 3 loading vector map source

1. Vector Map Vector graphics use straight lines ...

Complete steps for using Echarts and sub-packaging in WeChat Mini Program

Preface Although the holiday is over, it shows up...

4 Ways to Quickly Teach Yourself Linux Commands

If you want to become a Linux master, then master...

IDEA uses the Docker plug-in (novice tutorial)

Table of contents illustrate 1. Enable Docker rem...

The whole process of configuring hive metadata to MySQL

In the hive installation directory, enter the con...

Automatic failover of slave nodes in replication architecture in MySQL 8.0.23

I have been in contact with MGR for some time. Wi...

Detailed explanation of Docker daemon security configuration items

Table of contents 1. Test environment 1.1 Install...