ionic1頁面切換動畫卡頓優化

https://github.com/shprink/ionic-native-transitions
https://www.npmjs.com/package/ionic-native-transitions
這個是ionic1的, 推薦使用ionic2開發, 或者ionic-nativecss

Issue & solution

直接使用ionic的css動畫, 頁面數據較多的時候簡直卡成翔了, 使用分頁加載也沒有太大的改善.
目前最佳方案是使用[]ionic-native-transitions插件](https://github.com/shprink/ionic-native-transitions)html

install

# npm
npm install ionic-native-transitions --save

# Using Ionic CLI
ionic cordova plugin add https://github.com/Telerik-Verified-Plugins/NativePageTransitions#0.6.5

# 報錯Probably this is either a connection problem, or plugin spec is incorrect.
# 使用--nofetch來成功安裝
cordova plugin add https://github.com/Telerik-Verified-Plugins/NativePageTransitions#0.6.5 --save --nofetch

Import

能夠將ionic-native-transitions目錄copy到www\lib下, 再在index.html中引入android

<script src="lib/ionic-native-transitions/dist/ionic-native-transitions.min.js"></script>

config

angular.module('yourApp', [
    'ionic-native-transitions'
])

.config(function($ionicNativeTransitionsProvider){
    $ionicNativeTransitionsProvider.setDefaultOptions({
        duration: 400, // in milliseconds (ms), default 400,
        slowdownfactor: 4, // overlap views (higher number is more) or no overlap (1), default 4
        iosdelay: -1, // ms to wait for the iOS webview to update before animation kicks in, default -1
        androiddelay: -1, // same as above but for Android, default -1
        winphonedelay: -1, // same as above but for Windows Phone, default -1,
        fixedPixelsTop: 0, // the number of pixels of your fixed header, default 0 (iOS and Android)
        fixedPixelsBottom: 0, // the number of pixels of your fixed footer (f.i. a tab bar), default 0 (iOS and Android)
        triggerTransitionEvent: '$ionicView.afterEnter', // internal ionic-native-transitions option
        backInOppositeDirection: false // Takes over default back transition and state back transition to use the opposite direction transition to go back
    });

        $ionicNativeTransitionsProvider.setDefaultOptions({
            duration: 400, // in milliseconds (ms), default 400, 
            slowdownfactor: 4, // overlap views (higher number is more) or no overlap (1), default 4 
            iosdelay: -1, // ms to wait for the iOS webview to update before animation kicks in, default -1 
            androiddelay: -1, // same as above but for Android, default -1 
            winphonedelay: -1, // same as above but for Windows Phone, default -1, 
            fixedPixelsTop: 0, // the number of pixels of your fixed header, default 0 (iOS and Android) 
            fixedPixelsBottom: 0, // the number of pixels of your fixed footer (f.i. a tab bar), default 0 (iOS and Android) 
            triggerTransitionEvent: '$ionicView.afterEnter', // internal ionic-native-transitions option 
            backInOppositeDirection: false // Takes over default back transition and state back transition to use the opposite direction transition to go back 
        });
        $ionicNativeTransitionsProvider.setDefaultTransition({
            type: 'slide',
            direction: 'left'
        });
        $ionicNativeTransitionsProvider.setDefaultBackTransition({
            type: 'slide',
            direction: 'right'
        });
});

crosswork

若是你用了crosswork記得config.xml中添加:
Android
if you are using Crosswalk > 1.3 please add the following to your config.xmlios

<preference name="CrosswalkAnimatable" value="true" />

tab

咱們不指望tab也出現這個切換效果, 禁用tab先的動畫git

.state('home', {
    url: '/home',
    nativeTransitions: null,
    templateUrl: "templates/home.html"
})

相關文章
相關標籤/搜索