Javascript 引入多个代码参数
我有以下应用类和偏移量变量的代码,我正在尝试引入以下参数Javascript 引入多个代码参数,javascript,html,Javascript,Html,我有以下应用类和偏移量变量的代码,我正在尝试引入以下参数 resuableAnimationFunc('header', 70, 'header-hide', 'header-show') resuableAnimationFunc('footer', 300, 'footer-hide', 'footer-show') 但我似乎无法让他们工作。不确定我是否正确地写出了代码 jQuery(document).ready(function($){ function reusuableAnima
resuableAnimationFunc('header', 70, 'header-hide', 'header-show')
resuableAnimationFunc('footer', 300, 'footer-hide', 'footer-show')
但我似乎无法让他们工作。不确定我是否正确地写出了代码
jQuery(document).ready(function($){
function reusuableAnimationFunc(elementName, offset, hideClass, showClass) {
$animation = $(elementName);
$(window).scroll(function(){
( $(this).scrollTop() > offset ) ? $animation.addClass(hideClass).removeClass(showClass):
$animation.addClass(showClass).removeClass(hideClass);
});
}
reusuableAnimationFunc('header', 70, 'header-hide', 'header-show')
reusuableAnimationFunc('footer', 300, 'footer-hide', 'footer-show')
});
如果
页眉
和页脚
是HTML元素,则将代码包装在DOM ready中,如下所示:
$(function() {
resuableAnimationFunc('header', 70, 'header-hide', 'header-show')
resuableAnimationFunc('footer', 300, 'footer-hide', 'footer-show')
});
如果
页眉
和页脚
是HTML元素,则将代码包装在DOM ready中,如下所示:
$(function() {
resuableAnimationFunc('header', 70, 'header-hide', 'header-show')
resuableAnimationFunc('footer', 300, 'footer-hide', 'footer-show')
});
这些是html的元素,而不是类。这个类是标题显示等。我的问题更多的是这些行在我的代码中去了哪里。我试着把它放在我的代码后面,试着把它放在我的htmlOh中,我看到了,所以它们是HTML标签。您是否已将您的函数调用放入DOM ready中,例如
$(function(){ResubableAnimationFunct(…);})
?是的,我有,尽管我将更新我的问题,包括该部分。我只是不确定我是否将代码的参数行放在了正确的位置。我想我可以把它们放在代码后面,但它似乎不起作用,你的回答建议我运行另一个函数?你已经在DOM ready上包装了函数ResubableAnimationFunc
。您需要像我上面发布的那样,将函数调用包装在DOM ready中。这些是html的元素,而不是类。这个类是标题显示等。我的问题更多的是这些行在我的代码中去了哪里。我试着把它放在我的代码后面,试着把它放在我的htmlOh中,我看到了,所以它们是HTML标签。您是否已将您的函数调用放入DOM ready中,例如$(function(){ResubableAnimationFunct(…);})
?是的,我有,尽管我将更新我的问题,包括该部分。我只是不确定我是否将代码的参数行放在了正确的位置。我想我可以把它们放在代码后面,但它似乎不起作用,你的回答建议我运行另一个函数?你已经在DOM ready上包装了函数ResubableAnimationFunc
。您需要像我在上面发布的那样将函数调用包装在DOM ready中。这可能只是一个简单的输入错误。可重用在您的示例代码中有两种不同的拼写方式:可重用和可恢复。这可能只是一个简单的拼写错误。可重用在示例代码中有两种不同的拼写方式:可重用和可恢复。