原生页面切换效果
插件安装:
cordova plugin add com.telerik.plugins.nativepagetransitions
如果使用Cordova4+还需安装插件:
cordova plugin add cordova-plugin-whitelist
在index.html中添加
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
Full example:
nameApp.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// then override any default you want
window.plugins.nativepagetransitions.globalOptions.duration = 500;
window.plugins.nativepagetransitions.globalOptions.iosdelay = 350;
window.plugins.nativepagetransitions.globalOptions.androiddelay = 350;
window.plugins.nativepagetransitions.globalOptions.winphonedelay = 350;
window.plugins.nativepagetransitions.globalOptions.slowdownfactor = 4;
// these are used for slide left/right only currently
window.plugins.nativepagetransitions.globalOptions.fixedPixelsTop = 0;
window.plugins.nativepagetransitions.globalOptions.fixedPixelsBottom = 0;
});
});
$state.go('view', {movieid: id});
window.plugins.nativepagetransitions.slide(
{"direction":"up"},
function (msg) {console.log("success: " + msg)}, // called when the animation has finished
function (msg) {alert("error: " + msg)} // called in case you pass in weird values
);
添加指令
nameApp.directive('goNative', ['$ionicGesture', '$ionicPlatform', function($ionicGesture, $ionicPlatform) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
$ionicGesture.on('tap', function(e) {
var direction = attrs.direction;
var transitiontype = attrs.transitiontype;
$ionicPlatform.ready(function() {
switch (transitiontype) {
case "slide":
window.plugins.nativepagetransitions.slide({
"direction": direction
},
function(msg) {
console.log("success: " + msg)
},
function(msg) {
alert("error: " + msg)
}
);
break;
case "flip":
window.plugins.nativepagetransitions.flip({
"direction": direction
},
function(msg) {
console.log("success: " + msg)
},
function(msg) {
alert("error: " + msg)
}
);
break;
case "fade":
window.plugins.nativepagetransitions.fade({
},
function(msg) {
console.log("success: " + msg)
},
function(msg) {
alert("error: " + msg)
}
);
break;
case "drawer":
window.plugins.nativepagetransitions.drawer({
"origin" : direction,
"action" : "open"
},
function(msg) {
console.log("success: " + msg)
},
function(msg) {
alert("error: " + msg)
}
);
break;
case "curl":
window.plugins.nativepagetransitions.curl({
"direction": direction
},
function(msg) {
console.log("success: " + msg)
},
function(msg) {
alert("error: " + msg)
}
);
break;
default:
window.plugins.nativepagetransitions.slide({
"direction": direction
},
function(msg) {
console.log("success: " + msg)
},
function(msg) {
alert("error: " + msg)
}
);
}
});
}, element);
}
};
}]);
<ion-item item="group" collection-repeat="movie in movies" collection-item-width="'100%'" collection-item-height="100" href="#/movie/" class="item-thumbnail-left" transitiontype="flip" direction="left" go-native>
<ion-nav-bar class="bar-positive">
<ion-nav-back-button class="button-clear" transitiontype="flip" direction="right" go-native>
<i class="ion-arrow-left-c"></i> Back
</ion-nav-back-button>
</ion-nav-bar>
添加服务
nameApp.service('Navigation', function($state) {
//directly binding events to this context
this.goNative = function(view, data, direction) {
$state.go(view, data);
window.plugins.nativepagetransitions.slide({
"direction": direction
},
function(msg) {
console.log("success: " + msg)
}, // called when the animation has finished
function(msg) {
alert("error: " + msg)
} // called in case you pass in weird values
);
};
});
最后配置Config
nameApp.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
$ionicConfigProvider.views.transition('none');
}
如果文章对你有帮助,欢迎点击上方按钮打赏作者