cordva+vueアプリを構築して、実践ノートを作ります.
2040 ワード
生物理リターンキーのモニターを実現します.
var exitAppTicker = 0;
document.addEventListener("deviceready",function(){
document.addEventListener("backbutton", function(){
var pageUrl = window.location.href;
var n = pageUrl.lastIndexOf('?');
var m = pageUrl.lastIndexOf('/');
var str = ''
if (n > 0) {
str = pageUrl.substring(m+1,n); // pageName
} else {
str = pageUrl.substring(m+1); // pageName
}
if(str == 'index' || str == '' || str == 'loginPhone'){
if(exitAppTicker == 0){
exitAppTicker++;
showToast(' ', 2000)
setTimeout(function(){
exitAppTicker = 0;
},2000);
}else if(exitAppTicker == 1){
navigator.app.exitApp();
}
}else{
history.back();
}
}, false);
},false);
カスタムtoast、jsはandroidの中でtoast効果を実現します./**
* toast,js android toast
* @param msg
* @param duration
*/
function showToast(msg, duration) {
duration = isNaN(duration) ? 2000 : duration;
var m = document.createElement('div');
m.innerHTML = msg;
m.style.cssText = "width:60%; min-width:150px; background:#000; opacity:0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:70%; left:20%; z-index:999999; font-weight:bold;";
document.body.appendChild(m);
setTimeout(function() {
var d = 0.5;
m.style.webkitTransition = '-webkit-transform ' + d
+ 's ease-in, opacity ' + d + 's ease-in';
m.style.opacity = '0';
setTimeout(function() {
document.body.removeChild(m)
}, d * 1000);
}, duration);
}