问题描述
此处提供代码:
$('span.faqanswer').hide();
$('strong.faqlink').css('cursor','pointer').click(function(){
$(this).parent().find('span.faqanswer').slideToggle();
});
如果单击span.faqlink,它只会切换,而不会滑动.如果再次单击,它将滑动.这在任何过程中都会发生.向下滑动只是切换而向上滑动则切换...
If you click the span.faqlink it just toggles but not slidetoggles. if you click again it slidetoggles.this happens in any process. the downslide just toggles and the upslide slidetoggles...
推荐答案
jQuery的动画依赖于具有height
和width
的元素.由于span
是内联元素,因此没有设置或设置这些尺寸,因此动画将无法正常工作.
jQuery's animation relies upon the element having height
and width
. Since span
is an inline element, it does not have these dimensions set or settable, so animations won't work.
它可以在向上滑动时使用,因为显示设置为inline-block
并且可以设置动画.
It works while sliding up because the display is set to inline-block
and it can be animated.
如果可以更改标记,我建议您将span
包裹在div
中,然后滑动div
.
I would suggest you to wrap the span
in a div
and then slide the div
instead if it is possible to change your markup.
工作演示- http://jsfiddle.net/ShankarSangoli/yTeAY/
这篇关于jQuery slideToggle()不“滑动";进进出出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!