内容.toggleAnimationClass();不是一个函数

2024-04-04

我有html and css最基本的使用工作正常smoothState.js

;(function ($) {
 $('#main').smoothState();
})(jQuery);

然而,即使有了这个基本的实现,如果您选择当前页面的链接,(即重新加载页面)你会得到一个空白white屏幕与2015写在左上角。有这个错误控制台中没有记录错误这让我认为这是由smoothState.js

如果我扩展 smoothState 以允许更高级的选项,(即“正在退出”)现在无法浏览网站,无法离开页面。

通过高级实现,如本问题末尾所示,我收到控制台错误:

Uncaught TypeError: content.toggleAnimationClass is not a function main.js:134
    $.smoothState.onStart.render @ main.js:134
    load                         @ jquery.smoothState.js:533
    clickAnchor                  @ jquery.smoothState.js:589
    n.event.dispatch             @ jquery.min.js:3
    n.event.add.r.handle         @ jquery.min.js:3

这是html:

<head></head>
<body>
 <div id="main" class="m-scene">

  <header id="header">
  </header>

  <div id="page_content_container" class="scene_element scene_element--moveUpIn">

   <section class="about-intro-container">
   </section>

   <section class="about-services-container">
   </section>

   <section class="about-randomBits-container">
   </section>

   <footer>
   </footer>

  </div><!-- #page_content_container -->
 </div><!-- #main -->

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
 <script src="js/jquery.smoothState.js"></script>
 <script src="js/main.js"></script>

</body>
</html>

这是与 smoothState 相关的css:

/* prefixes are just missing here, I have them in my file */

.m-scene .scene_element {
  animation-duration: .5s;
  transition-timing-function: ease-in;
  animation-fill-mode: both;
}

.m-scene .scene_element--moveUpIn {
  animation-name: moveUp, fadeIn;
}

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

@keyframes moveUp {
  0% {
    transform: translateY(100%) 
  }
  100% { 
    transform: translateY(0%) 
  }
}

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

这是更高级的 smoothState:

;(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);

最终我计划添加prefetch, 页面缓存大小等等...并根据您正在加载/退出的页面实现不同的转换。然而,目前在我能够解决上述问题之前,不值得继续前进。

欢迎任何想法或帮助,非常感谢,Thanks.

哦,我也刚刚收到这个错误

XMLHttpRequest cannot load file:///Users/Parallelos/Developer/paralellos.github.io/projects.html.
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
  n.ajaxTransport.k.cors.a.crossDomain.send @ jquery.min.js:4
  n.extend.ajax                             @ jquery.min.js:4
  fetch                                     @ jquery.smoothState.js:355
  load                                      @ jquery.smoothState.js:529
  clickAnchor                               @ jquery.smoothState.js:589
  n.event.dispatch                          @ jquery.min.js:3
  n.event.add.r.handle                      @ jquery.min.js:3

我处理过这个完全相同的问题。如果您下载演示并浏览其“functions.js”,您会注意到处理现有 css 类的不同方式。这是该代码,已经对其进行了测试,它对我有用。

$(function(){
  'use strict';
  var $page = $('#main'),
      options = {
        debug: true,
        prefetch: true,
        cacheLength: 2,
        forms: 'form',
        onStart: {
          duration: 250, // Duration of our animation
          render: function ($container) {
            // Add your CSS animation reversing class
            $container.addClass('is-exiting');
            // Restart your animation
            smoothState.restartCSSAnimations();
          }
        },
        onReady: {
          duration: 0,
          render: function ($container, $newContent) {
            // Remove your CSS animation reversing class
            $container.removeClass('is-exiting');
            // Inject the new content
            $container.html($newContent);
          }
        }
      },
      smoothState = $page.smoothState(options).data('smoothState');

});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

内容.toggleAnimationClass();不是一个函数 的相关文章

  • 无法解构“undefined”或“null”的属性“user”

    使用 redux 检索用户信息时出错 我想从数据库获取用户信息 姓名 密码和头像地址 然后对其进行编辑 我正在使用nodejs express react redux 和jwt Actions user js import axios fr
  • 在 Javascript 中缓存和预取过期的 Promise

    Promise 是我在 Javascript 中管理异步代码的首选方式 Memoize npm 上的 memoizee 是一个 Javascript 库 用于轻松缓存和预取函数结果 理想情况下 我想结合两者的优点 并且能够使 Promise
  • 关闭模态后清除模态字段

    我有这个模式
  • Sonarqube 未从 LCOV 检索我的 JavaScript 覆盖范围

    我有一个具有以下结构的应用程序 my application pom xml app scripts app js js 3rd party libs build node modules test 我已经创建了pom xml仅运行 Son
  • 如何在javascript中解压二进制文件?

    我正在尝试将一些现有代码从 python 移植到 javascript 并且不确定如何处理以下行 var1 var2 struct unpack
  • preg_match_all JS 等效吗?

    Javascript 中是否有与 PHP 的 preg match all 等效的函数 如果没有 将正则表达式的所有匹配项放入数组的最佳方法是什么 我愿意使用任何 JS 库来让它变得更容易 您可以使用match使用全局修饰符 gt gt g
  • 如何对结构切片而不是切片结构进行范围调整

    稍微玩了一下 Go HTML 模板后 我发现的所有循环模板中对象的示例都是将切片结构传递给模板 有点像这个示例 type UserList struct Id int Name string var templates template M
  • 高度在 IOS (iphone) 上无法正常工作

    我已经创建了this https codepen io salman15 project live DWbWpo Codepen 上的网站 在尝试使其响应所有平台时 我遇到了问题 看起来单个 div 覆盖了整个页面 仅在 IOS 上 并且并
  • 如何在单元测试中的请求之间更改 $httpBackend when[method] 语句?

    在我的测试中 我启动一些模型数据并模拟响应 beforeEach function var re new RegExp http users online httpBackend whenGET re respond id 12345 us
  • CSS 3 nth 类型仅限于类 [重复]

    这个问题在这里已经有答案了 有没有办法限制 CSS 3nth of type去上课 我有一个动态数量section具有不同类别的元素指定其布局需求 我想抓住三分之一 module 但似乎nth of type查找类元素类型 然后计算类型 相
  • jQuery - 动画可折叠 DIV,向上滑动?

    我使用这个 jQuery 脚本来设置 div 的动画 以便在用户单击按钮时打开 关闭 http www dynamicdrive com dynamicindex17 animatedcollapse htm http www dynami
  • 无需递归即可展平多个嵌套数组的数组 - javascript

    也许这是一个愚蠢的问题 但我无法意识到是否可以在不使用递归的情况下展平多维数组 我用递归编写了一种解决方案 function transform arr var result arr forEach flatten function fla
  • 单击按钮滚动到特定 div

    我有一个具有固定菜单和内容框 div 的页面 单击菜单时 内容框滚动到特定 div 到目前为止 一切都很好 这是这里的示例 https jsfiddle net ezrinn 8cdjsmb9 11 https jsfiddle net e
  • CSS:结合纹理和颜色

    有人如何将用作背景图像的纹理和该纹理上方的背景颜色结合起来 这是纹理 我希望我的正文背景页面是这样的 我正在努力处理背景图像和背景颜色 http jsfiddle net 87K72 http jsfiddle net 87K72 body
  • Python Flask 不更新图像[重复]

    这个问题在这里已经有答案了 这里有一些关于图像的 Flask 问题 但没有一个能解决我的问题 我有一个应用程序可以创建图像 保存它 然后显示它 一次 它应该多次执行此操作 每次更改图像时 它应该加载新图像 它不是 它只显示与其显示的文件名关
  • localhost/test.php 不返回任何内容

    我正在遵循教程构建一个网络应用程序 我创建了一个简单的test php网络空间中的文件 var www html 问题是当我输入localhost test php在浏览器地址窗口中 它返回一个空页面 我试过localhost php in
  • 如何检索 JQuery 数据表的排序状态

    我对 JQuery Datatables 还很陌生 我正在尝试检索有关数据表的两个信息 当前正在对哪个列索引进行排序 也称为选择 排序顺序 升序或降序 不知道我应该如何解决这个问题 使用 jquery 查找列索引 或者 Datatables
  • 有两个切边的矩形

    我不确定这个形状的具体名称是什么 但我可以将其称为 半平行四边形 吗 我想纯粹使用这个形状CSS CSS3 有什么帮助吗 或教程 您可以使用伪元素来完成此操作 如下所示 做法是从盒子的左下角和右上角剪出一个三角形 只要主体背景是纯色 此方法
  • Shiny 中的模态对话框:可以调整宽度但不能调整高度

    在我的 Shiny 应用程序中 我有几个来自闪亮BS 包的模式窗口 我可以像这样调整这些模式窗口的宽度 tags head tags style HTML modal lg width 1200px abs 1 background col
  • 当页面加载图像时,它是只加载一次,还是每次在标记中找到它时加载?

    当页面加载图像时 它是只加载一次 还是每次在标记中找到它时加载 那么 jquery 呢 附加一个 img 会导致它再次重新加载吗 我问这个问题是因为我有高分辨率图像 但需要在标记的许多情况下使用它 img src hello jpg img

随机推荐