简体   繁体   English

过滤时出现奇怪的Isotope.js动画

[英]Weird Isotope.js Animation when filtering

When I am setting up this filter and using it, the functionality works except for one thing. 当我设置并使用此过滤器时,该功能可以正常工作,只有一件事。 There is a weird animation during the filter process. 筛选过程中出现奇怪的动画。

In my codepen the code works great. 在我的Codepen中 ,代码效果很好。 Copied and pasted with the same JS version and the same build version. 复制并粘贴相同的JS版本和相同的构建版本。

In my website it does not work. 在我的网站上不起作用。 Now I've gone through and disabled all plugins and every script that is being called besides my code, which was placed in an isolated .js file, and the CSS files. 现在,我遍历并禁用了所有插件和除我的代码(被放置在独立的.js文件和CSS文件中)之外的所有脚本。

I am not sure what exactly the issue is anymore and can't figure out how to isolate the issue further to identify the problem. 我不确定问题到底是什么,也无法弄清楚如何进一步隔离问题以找出问题。

I am running the website on WordPress, version 4.7.5 我正在WordPress版本4.7.5上运行网站

Below is my javascript. 以下是我的JavaScript。 It's the only thing I am calling. 这是我唯一要打电话的东西。

(function($){
  'use strict';

    var grid = jQuery('.masonry').isotope(),
        $win = jQuery(window);

    jQuery('.filter span a').click(function(){
    jQuery( this ).parents( 'div.filter' ).find( 'span a' ).removeClass( 'active' );
    jQuery( this ).addClass( 'active' );

    grid.isotope({
      filter: jQuery(this).attr('data-filter'),
      layoutMode: 'fitRows',
    })
  });
});

Remove the <link rel='stylesheet' id='isotope-style-css' ...> CSS. 删除<link rel='stylesheet' id='isotope-style-css' ...> CSS。

Unless you specify that you are only using CSS ( see animationEngine in the Metafizzy docs ) then it's going to load both the jQuery animation and the CSS -- causing the weirdness. 除非您指定仅使用CSS( 请参阅Metafizzy文档中的animationEngine ),否则它将同时加载jQuery动画和CSS -导致异常。 You can test out this fact by checking out your CodePen duplicated here with the weirdness because I added the CSS: http://codepen.io/carasmo/pen/KmrPRb 您可以通过检查您在此处重复的CodePen来验证这一事实,这很奇怪,因为我添加了CSS: http ://codepen.io/carasmo/pen/KmrPRb

You have an error in console: «Uncaught TypeError: Cannot read property 'firstChild' of null» . 您在控制台中出错: «未捕获的TypeError:无法读取null的属性'firstChild'

This is because you try to initiate a Google Map on an inexistant element #map-canvas . 这是因为您尝试在不存在的元素#map-canvas上启动Google Map。

To fix that... What I would do is to remove lines #881 to #1183, which is your Google Map API initialisation script, from the script.js . 要解决此问题...我要做的是从script.js删除#881至#1183行,这是您的Google Map API初始化脚本。

I would place this in a map.js which I would call only on the page(s) where there actually is an element with id map-canvas . 我将其放置在map.js中,我只会在实际上存在ID为map-canvas的元素的页面上调用它。

For now, this error just halts the loading of script.js. 目前,此错误只是停止了script.js的加载。
So the document.ready() function isn't closed properly. 因此, document.ready()函数未正确关闭。

You used (function($){ which is the same as document.ready() on line #209. 您使用了(function($){与第#209行上的document.ready()相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM