[英]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?
我使用不正确吗?
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.