简体   繁体   English

jQuery slideUp和fadeOut“不起作用”?

[英]JQuery slideUp and fadeOut 'not working'?

So in my Javascript, I have this 所以在我的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();
});

Now, the screenSlide function is this 现在,screenSlide函数是这个

$.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 = "#" + test;
    $(test).slideUp(); // slide it up, hide it and remove the .current class from the <li> element
    $(test).hide();
    $(test).removeClass('current');
    var gettingShown = $(this).attr('id');
    gettingShown = "#" + gettingShown + "Slide";
    $(gettingShown).addClass('current'); // add the .current class to $(this) <li>
    $(gettingShown).slideDown();
};

Now, gettingShown does slide up and when I click another < li > then the screen which slid up (gettingShown) does hide, but it doesn't slideUp. 现在,gettingShown确实会向上滑动,当我单击另一个<li>时,会向上滑动的屏幕(gettingShown)会隐藏,但不会滑动。 Which means that 意思就是

$(test).hide();

is working however 正在工作

$(test).slideUp();

is not working, right? 不起作用,对吗? Why is that? 这是为什么? I also tried changing slideUp to fadeOut but that still didn't work. 我也尝试将slideUp更改为fadeOut,但这仍然行不通。 I change slideDown to fadeIn and it worked. 我将slideDown更改为fadeIn并成功了。 How come slideUp and fadeOut aren't working? slideUp和fadeOut怎么不起作用? Am I using it incorrectly? 我使用不正确吗?

slideUp() is async, and it hides the element on completion of sliding up. slideUp()是异步的,并且在向上滑动完成时会隐藏元素。

It should be 它应该是

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

This is a cleaner version of the bound event and actions. 这是绑定事件和操作的更干净的版本。

$('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
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM