首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SmoothState.JS切换动画不起作用

SmoothState.JS切换动画不起作用
EN

Stack Overflow用户
提问于 2015-02-22 04:47:57
回答 1查看 1.2K关注 0票数 2

我尝试将smoothState.js嵌入到我的项目中。但由于任何原因,“动画方向:交替反转;”不起作用(或其他原因)。元素只是淡入而不是淡出。我什么都试过了,但都不管用。

html

代码语言:javascript
复制
<div id="main" class="m-scene">
  <a href="archive02.php">archive</a>
  <div class="scene_element scene_element--fadein">
    <div class="project_headline">
        <p>P01</p>
    </div>
  </div>
</div>
代码语言:javascript
复制
    <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.1.min.js"><\/script>')</script>
    <script src="jquery.smoothState.js"></script>
    <script src="functions.js"></script>
    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
    <script>
        (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
        function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
        e=o.createElement(i);r=o.getElementsByTagName(i)[0];
        e.src='//www.google-analytics.com/analytics.js';
        r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
        ga('create','UA-XXXXX-X');ga('send','pageview');
    </script>

Css

代码语言:javascript
复制
m-scene .scene_element {
  animation-duration: 5.25s;
  -webkit-animation-duration: 5.25s;
  -moz-animation-duration: 5.25;
  transition-timing-function: ease-in;
  -webkit-transition-timing-function: ease-in;
  -moz-transition-timing-function: ease-in;
  animation-fill-mode: both;
  -webkit-animation-fill-mode: both;
  -moz-animation-fill-mode: both;
}

.m-scene .scene_element--fadein {
  animation-name: fadeIn;
  -webkit-animation-name: fadeIn;
  -moz-animation-name: fadeIn;
}

.m-scene.is-exiting .scene_element {
  animation-direction: alternate-reverse;
  -webkit-animation-direction: alternate-reverse;
  -moz-animation-direction: alternate-reverse;
}

/*
 * Keyframes
 */
@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@-webkit-keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@-moz-keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

JS

代码语言:javascript
复制
// Contents of functions.js
;(function($) {
  'use strict';
  var $body = $('html, body'),
      content = $('#main').smoothState({
        // Runs when a link has been activated
        onStart: {
          duration: 250, // Duration of our animation
          render: function (url, $container) {
            // toggleAnimationClass() is a public method
            // for restarting css animations with a class
            content.toggleAnimationClass('is-exiting');
            // Scroll user to the top
            $body.animate({
              scrollTop: 0
            });
          }
        }
      }).data('smoothState');
      //.data('smoothState') makes public methods available
})(jQuery);

希望有人能帮助我:)

EN

回答 1

Stack Overflow用户

发布于 2015-03-16 04:18:22

我在使用smoothState.js时也遇到了类似的问题。在我的例子中,我只需要将脚本从页眉移到页脚下面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28651161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档