利用Animsition 插件,为页面切换添加转场动画

厌倦了死板的页面转场?试试利用Animsition给你的网页添加转场动画吧!

Demo:https://demo.buyao.vip/animsition/
1 - 利用Animsition 插件,为页面切换添加转场动画

使用方法:

下载JS插件并上传:点击下载 分流下载

步骤1:链接所需的文件

<!-- animsition.css -->
<link rel="stylesheet" href="./dist/css/animsition.min.css">
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!-- animsition.js -->
<script src="./dist/js/animsition.min.js"></script>

步骤2:HTML标记

<body>
  <div class="animsition">
    <a href="./page1" class="animsition-link">animsition link 1</a>
    <a href="./page2" class="animsition-link">animsition link 2</a>
  </div>
</body>

如果要每个“ linkElement”使用不同的动画。

<a
  href="./page1"
  class="animsition-link"
  data-animsition-out-class="fade-out-right"
  data-animsition-out-duration="2000"
>
  animsition link 1
</a>

<a
  href="./page2"
  class="animsition-link"
  data-animsition-out-class="rotate-out"
  data-animsition-out-duration="500"
>
  animsition link 2
</a>

如果要在每个页面上使用不同的动画。

<div
  class="animsition"
  data-animsition-in-class="fade-in"
  data-animsition-in-duration="1000"
  data-animsition-out-class="fade-out"
  data-animsition-out-duration="800"
>
  ...
</div>

步骤3:呼叫动画

$(document).ready(function() {
  $(".animsition").animsition({
    inClass: 'fade-in',
    outClass: 'fade-out',
    inDuration: 1500,
    outDuration: 800,
    linkElement: '.animsition-link',
    // e.g. linkElement: 'a:not([target="_blank"]):not([href^="#"])'
    loading: true,
    loadingParentElement: 'body', //animsition wrapper element
    loadingClass: 'animsition-loading',
    loadingInner: '', // e.g '<img src="loading.svg" />'
    timeout: false,
    timeoutCountdown: 5000,
    onLoadEvent: true,
    browser: [ 'animation-duration', '-webkit-animation-duration'],
    // "browser" option allows you to disable the "animsition" in case the css property in the array is not supported by your browser.
    // The default setting is to disable the "animsition" in a browser that does not support "animation-duration".
    overlay : false,
    overlayClass : 'animsition-overlay-slide',
    overlayParentElement : 'body',
    transition: function(url){ window.location.href = url; }
  });
});

大事记

INSTART

$('.foo').on('animsition.inStart', function(){})

INEND

$('.foo').on('animsition.inEnd', function(){})

OUTSTART

$('.foo').on('animsition.outStart', function(){})

OUTEND

$('.foo').on('animsition.outEnd', function(){});

方法

IN

$('.foo').animsition('in');

OUT

$('.foo').animsition('out', $elem, url);