[英]Javascript isn't working in Firefox/IE but works in Chrome
For some reason my nav collapse function isn't working in Firefox/IE but works in Chrome. 出于某种原因,我的导航折叠功能在Firefox / IE中不起作用,但在Chrome中有效。
<script type="text/javascript">
$(function(){
$('#header').data('size','big');
});
$(window).scroll(function(){
var $nav = $('#header');
if ($('body').scrollTop() > 0) {
if ($nav.data('size') == 'big') {
$('#logo').fadeOut(300);
$nav.data('size','small').stop().animate({
height:'95px'
}, 600);
}
} else {
if ($nav.data('size') == 'small') {
$('#logo').fadeIn(300);
$nav.data('size','big').stop().animate({
height:'185px'
}, 600);
}
}
});
</script>
Any ideas? 有任何想法吗? I'm thinking it's a syntax error.
我认为这是一个语法错误。
You can see the live example in the navigation at http://medialimes.com 您可以在http://medialimes.com的导航中查看实时示例
Try using $(window).scrollTop()
instead of $('body').scrollTop()
. 尝试使用
$(window).scrollTop()
而不是$('body').scrollTop()
。 This should work on both Chrome and Firefox/IE. 这应该适用于Chrome和Firefox / IE。
My guess is that when you try to set 我的猜测是,当你尝试设置
$('#header').data('size','big')
doesn actually set the data variable properly. 实际上并没有正确设置数据变量。
Try setting it using the attr method. 尝试使用attr方法设置它。
$(#header).attr('size','big');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.