【发布时间】:2023-03-08 16:50:01
【问题描述】:
希望大家过得愉快
我想为那段代码添加动画。我尝试使用 animate() 。但是没有用,可能是因为我对javascript缺乏了解。
请告诉我是否可以使用此代码,或者我需要尝试其他方法吗?你有什么建议?
非常感谢您。
这是 HTML 代码:
<div id="description_wrapper">
Text content.<br/>
See; More Text content.
</div>
<button class="learn_more" id="lm_more" href="#">Learn more</button>
CSS
#description_wrapper
{
margin: 0 auto;
margin-top: 25px;
height: 0;
overflow: hidden;
}
jQuery
$('#lm_more').click(function(event){
event.preventDefault();
if($('#description_wrapper').css('height') > '1px') {
$('#description_wrapper').css({'height': '0px'});
$('#lm_more').html('Learn More');
}
else
{
$('#description_wrapper').css({'height': 'auto'});
$('#lm_more').html('Learn less');
}
});
【问题讨论】:
-
jQuery 只对实际数字进行动画处理,它不理解“自动”,如果这是你尝试的动画?
-
如果您要设置动画效果,可以使用 CSS3 转换来自动设置动画
标签: jquery css jquery-animate