我需要你的帮助。我正在尝试添加一些动画来点击事件。我可以很容易地用切换,但我的问题是,我有2个不同的名称和样式的按钮,我需要当点击其他节目和按钮点击隐藏。这里是我的代码,这样就可以更好地理解它:jQuery切换不同的链接
我的标记是只有2个链接:
<a href="#" class="show-more"><?php print t('Show more'); ?></a>
<a href="#" class="show-less"><?php print t('Show less'); ?></a>
谁能帮助我在这?我需要帮助把这个工作与动画(如jQuery切换是好的)和性能的建议。提前致谢。
UPDATE
新的更新
我找到一种方法来复制我所需要的,这里是代码:
$('.user-profile .resume p').each(function() {
var $obj = $(this);
var height = $obj.height();
var maxHeight = 40;
if (height > 40) {
$obj.css('height', maxHeight).css('overflow', 'hidden');
$obj.siblings('.show-more').show();
}
$obj.siblings('.show-more').click(function(e) {
e.preventDefault();
$obj.animate({
'height' : height
}, function() {
$obj.siblings('.show-more').hide();
$obj.siblings('.show-less').show();
});
});
$obj.siblings('.show-less').click(function(e) {
e.preventDefault();
$obj.animate({
'height' : maxHeight
}, function() {
$obj.siblings('.show-more').show();
$obj.siblings('.show-less').hide();
});
});
});
这里是一个fiddle与这最后的代码。
任何人都可以帮助我改进此代码吗?非常感谢。
你能在小提琴发布工作的例子,你的问题犯规使问题清晰。我的猜测是,最好有一个按钮,并根据相关的div是否可见/隐藏来改变功能。 –
发布您的HTML或创建[fiddle](http://jsfiddle.net)。 –
感谢您的回答,我用jsfiddle更新了最初的帖子。 – Mambley