Javascript JQuery slideUp和fadeOut';不工作;?

Javascript JQuery slideUp和fadeOut';不工作;?,javascript,jquery,fadeout,slideup,Javascript,Jquery,Fadeout,Slideup,所以在我的Javascript中,我有 $('ul li').click(function(){ //loops through all <li>'s inside a <ul> $('ul .clicked').removeClass('clicked'); // when an <li> is clicked, remove .clicked class from any other <li>'s $(this).addCla

所以在我的Javascript中,我有

$('ul li').click(function(){ //loops through all <li>'s inside a <ul>

    $('ul .clicked').removeClass('clicked'); // when an <li> is clicked, remove .clicked class from any other <li>'s
    $(this).addClass('clicked'); // add .clicked class to the clicked <li> ($(this))

    $(this).screenSlide();
});
然而,它正在发挥作用

$(test).slideUp();
不起作用,对吗?为什么呢?我也试着将slideUp改为淡出,但仍然不起作用。我把slideDown改为fadeIn,效果很好。为什么slideUp和fadeOut不起作用?我是否使用不正确?

是异步的,它在向上滑动完成时隐藏元素

应该是

$(test).slideUp(function () {
    $(this).removeClass('current');
});

这是绑定事件和操作的更清晰版本

$('ul > li').click(function() { //loops through all <li>'s inside a <ul>
    $('li').removeClass('clicked'); // when an <li> is clicked, remove .clicked class from any other <li>'s
    $(this).addClass('clicked').screenSlide(); // add .clicked class to the clicked <li> ($(this))
});

$.fn.screenSlide = function() { // $(this) = aboutSectorNineteen (<li>'s id)
    var test = $('.current').attr('id'); //if an element with .current as it's class exists, let test be equal to that elements id
    $('#' + test).slideUp().removeClass('current'); // slide it up, hide it and remove the .current class from the <li> element
};
$('ul>li')。单击(function(){//在
    $('li').removeClass('clicked');//单击
  • 时,从任何其他
  • 中删除.clicked类 $(this).addClass('clicked').screensile();//将.clicked类添加到单击的
  • ($(this)) }); $.fn.screenSlide=function(){/$(this)=关于系数十九(
  • 的id) var test=$('.current').attr('id');//如果存在类为.current的元素,则让test等于该元素id $('#'+test).slideUp().removeClass('current');//将其向上滑动,隐藏并从
  • 元素中删除.current类 };
请显示您的HTML标记。@DevlshOne,嗯,看起来Arun已经得到了答案。他说的很管用。哦,很有趣,很管用。谢谢那么,为什么仅仅$(test).slideUp()会自动将其向上滑动然后隐藏呢?为什么我必须在slideUp参数中创建函数?@user2817200传递给
slideUp
的函数是一个回调函数,当滑动完成时将执行该函数…对。。但是忽略removeClass部分,为什么$(test).slideUp()一开始甚至不将其向上滑动并隐藏?当我在参数中放置一个空函数时,它是如何工作的,比如:$(this).slideUp(function(){});。。为什么添加一个空函数作为slideUp的参数会使它实际上向上滑动,但当没有空函数作为参数时,它就不起作用了?@user2817200如果删除
$(test).hide(),它与空函数无关您的代码应该是fineAh,这看起来更有条理。谢谢
$(test).slideUp(function () {
    $(this).removeClass('current');
});
$('ul > li').click(function() { //loops through all <li>'s inside a <ul>
    $('li').removeClass('clicked'); // when an <li> is clicked, remove .clicked class from any other <li>'s
    $(this).addClass('clicked').screenSlide(); // add .clicked class to the clicked <li> ($(this))
});

$.fn.screenSlide = function() { // $(this) = aboutSectorNineteen (<li>'s id)
    var test = $('.current').attr('id'); //if an element with .current as it's class exists, let test be equal to that elements id
    $('#' + test).slideUp().removeClass('current'); // slide it up, hide it and remove the .current class from the <li> element
};