【问题标题】:Wordpress Jquery Animation without scrollingWordpress Jquery 动画无需滚动
【发布时间】:2015-03-04 17:54:51
【问题描述】:

所以我制作了一个 wordpress 网站,其中包含一些运行良好的动画。 它们仅在我滚动网站并看起来像这样时才起作用:

jQuery(document).ready(function($){  


    $(window).scroll( function(){

        if(!isMobile) {
        $('.animate_1').each( function(i){

            var bottom_of_object = $(this).position().top + $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();

            /* If the object is completely visible in the window, fade it it */
            if( bottom_of_window > bottom_of_object ){

                $(this).animate({opacity:'1', margin: '0 3% 0 3%'},2000, 'easeInOutQuart');

            }   

        })
        } 
        })
    });

这工作得很好。现在我想在网站加载时为我称为“.aniamte_2”的类制作动画,无需任何滚动或点击。我试过这样:

jQuery(document).ready(function($){  

                $('.animate_2').animate({opacity:'1', margin: '0 3% 0 3%'},2000, 'easeInOutQuart');  
    }); 

由于某种原因它没有工作。 Chrome 告诉我 "$" 是 undefiend 什么的。

有人知道如何在不滚动的情况下制作动画?

【问题讨论】:

  • 尝试在头部加载 jquery,至少用于调试
  • 将第二个 JS 放在页脚中,并确保在此之前没有加载任何其他库,因为错误清楚地表明它无法找到 $

标签: javascript jquery css wordpress animation


【解决方案1】:

如果浏览器无法识别 $,则说明 jQuery 没有加载;出现这种情况的原因有很多。

【讨论】:

  • 只有在我包含我的代码的第二部分后,它才开始给我这个错误。没有它一切正常。
  • @BooooomxD 你能包括你的其余代码吗?如果您将完整的 js 放在包含新函数调用和与之相关的 html 之后,则更容易看出哪里出错了。
猜你喜欢
  • 2011-12-24
  • 1970-01-01
  • 2011-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多