所以当我点击包装器时我试图滑下我的标题,然后当我再次点击时它向上滑动。它仅在我第一次点击时才起作用,然后它继续向下滑动标题。
这是代码:
var header = $("header");
$("wrapper").on("click", function () {
if (header.css({"top" : "-8%"})) {
header.animate({"top" : "0%"}, 500);
} else if (header.css("top") == '0%') {
header.animate({"top" : "-8%"}, 500);
};
});
答案 0 :(得分:1)
试试这个:
$(".wrapper").click( function ()
{
if ( $(".header").css( 'top' ) == '-8%' )
$(".header").animate( {'top' : '0%'}, 500);
else
$(".header").animate( {'top' : '-8%'}, 500);
} );
我认为'包装'和'标题'这些课程是我加入$(" .header")的原因。如果您已对其进行了标记,请写入$("#header")。
对不起我的英语,我是法国人。