jQuery动画顶栏
我有一个顶部导航栏,当我点击它时,它需要向上移动jQuery动画顶栏,jquery,html,jquery-animate,Jquery,Html,Jquery Animate,我有一个顶部导航栏,当我点击它时,它需要向上移动 var foo = false $(document).ready(function(){ $(".topBar").click(function(){ findOut(); }); }); function up() { $(".topBar").animate({height:5},"slow"); } function down() { $(".topBar").animate({h
var foo = false
$(document).ready(function(){
$(".topBar").click(function(){
findOut();
});
});
function up()
{
$(".topBar").animate({height:5},"slow");
}
function down()
{
$(".topBar").animate({height:30},"slow");
}
function findOut()
{
if (foo===true)
{
down();
up = false;
}
elseif (foo===false)
{
up();
up = true;
}
}
在您询问之前,是的,我已经安装了jQuery文件
这是我的网站:SurrnTC.NET的最高级栏。
你有没有考虑过:
$("#topBar").click(function()
{
$(this).slideToggle()
});
这将使你的酒吧上升或下降,而不需要使用旗帜
如果您不想一直滑动它,那么代码看起来很好,除了elseif(up==false)
中缺少空白
如果你在你的网站上尝试,你会发现即使你将高度设置为5px,文本仍然可见,我建议你添加一个overflow:hidden
,这样它就可以保持隐藏状态
编辑
工作代码:
var up = false
$(document).ready(function(){
$(".topBar").click(function(){
findOut();
});
});
function upFunc()
{
$(".topBar").animate({height:5},"slow");
}
function down()
{
$(".topBar").animate({height:30},"slow");
}
function findOut()
{
if (up===true)
{
down();
up = false;
}
else if (up===false)
{
upFunc();
up = true;
}
}
您正在重新定义up变量,使其等于up()函数。 可能改为:
var isup = false;
elseif(up==false)
您缺少一个空格,它应该是}否则如果(){
是的,但我不能让它一直滑下去。那么我唯一能看到的是,在其他
我修复了它之后,你缺少了一个空格,但它仍然不起作用..啊,编码器的生命。其他
问题仍然存在。我将用我刚刚在你的页面中尝试过的代码编辑答案,它已经成功了我(还添加了溢出:隐藏)非常感谢!我已经习惯了Lua,其中elseif是一个词。无论如何,谢谢!