jQuery slideToggle()不“滑动";进进出出 [英] jquery slideToggle() not "sliding" in but out

查看:60
本文介绍了jQuery slideToggle()不“滑动";进进出出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处提供代码:

$('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的动画依赖于具有heightwidth的元素.由于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()不“滑动";进进出出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆