【发布时间】: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