首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Smoothstate.js - removeClass不工作的onReady函数

Smoothstate.js - removeClass不工作的onReady函数
EN

Stack Overflow用户
提问于 2018-02-07 20:23:24
回答 1查看 316关注 0票数 1

我正在使用Smoothstate.js向我的网站添加页面过渡,并尝试使用onStart、onProgress和onReady函数显示每个页面过渡之间的加载页面。

我的代码可以工作,但它会时不时地卡在加载页面上,并且容器div不会删除“is- loading”类。然而,它正在删除is - with类,即使它们使用相同的removeClass行?

我很困惑为什么它不能被移除。有谁能帮帮忙吗?

代码语言:javascript
复制
// Photoswipe
$(function(){
  'use strict';
  var options = {
    prefetch: true,
    debug:true,
    cacheLength: 0,
    repeatDelay: 500,


    onStart: {
      duration: 0, // Duration of our animation
      render: function ($container) {
        // Add your CSS animation reversing class
        $container.addClass('is-exiting');

        // Restart your animation
        smoothState.restartCSSAnimations();
      }
    },

    onProgress: {
    // How long this animation takes
    duration: 0,
    // A function that dictates the animations that take place
    render: function ($container) {
            setTimeout(function() { 
                    $container.addClass('is-loading');

                    $('#progressBar').append('<div id="bar"></div>');   
                    var progress = '100%';

                    $('#bar').animate({
                        width: progress
                    }, 400);
    }, 500);
    }
    },

    onReady: {
      duration: 0,
      render: function ($container, $newContent) {
        $container.removeClass('is-loading is-exiting');
        // Inject the new content
        $container.html($newContent);
      },
    },

    onAfter: function() {
            navbarAnimate();
            closeMenu();
            ImageSliders();
            initPhotoSwipeFromDOM('.gallery');
            ImageOverlay(); 
    }
  },


  smoothState = $('#main').smoothState(options).data('smoothState');
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-07 21:08:24

给你个提示:

在加载过程开始后500ms,添加is-loading。那么,有没有可能在你的500ms超时之前onReady就被解雇了呢?因此,在removeClass调用之后,是否会再次将- your添加为类?

tl;dr:问题很可能是这里的超时

代码语言:javascript
复制
setTimeout(function() { 
  $container.addClass('is-loading');

  $('#progressBar').append('<div id="bar"></div>');   
  var progress = '100%';

  $('#bar').animate({
    width: progress
  }, 400);
}, 500);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48663729

复制
相关文章

相似问题

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