jQuery切换函数仅将css分配给元素一秒钟(然后将其删除)?
我有这个HTML:jQuery切换函数仅将css分配给元素一秒钟(然后将其删除)?,jquery,Jquery,我有这个HTML: <div class="user-contribution"> <p class="user-review"> Review</p> 2. Animate this <a class="user-review-toggle" href="#">Read more...</a> // 1. Clicking this 这是: $(".user-review-toggl
<div class="user-contribution">
<p class="user-review"> Review</p> 2. Animate this
<a class="user-review-toggle" href="#">Read more...</a> // 1. Clicking this
这是:
$(".user-review-toggle").toggle(function(){
$(this).css("backgroundPosition", "0 -12px");
$(this).prev('.user-review').animate({height:150},200);
$(this).prev('.user-review').css("overflow", "visible");
},function(){
$(this).css("backgroundPosition", "0 0");
$(this).prev('.user-review').animate({height:98},200);
$(this).prev('.user-review').css("overflow", "hidden");
});
出于某种原因,当我单击.user review切换
链接时,溢出:可见
仅应用于用户查看
div几秒钟,然后它返回到隐藏状态(我应该保持可见)
有什么建议可以解决这个问题吗?没有确切的原因,但是如果您在动画的
oncomplete
-回调中应用溢出更改,它就会工作。至少,如果我理解你的问题
$(".user-review-toggle").toggle(function(){
$(this).css("backgroundPosition", "0 -12px");
$(this).prev('.user-review').animate({height: 150}, 200, function () {
$(this).css("overflow", "visible");
});
}, function(){
$(this).css("backgroundPosition", "0 0");
$(this).prev('.user-review').animate({height: 98}, 200, function () {
$(this).css("overflow", "hidden");
});
});
嘿,它成功了。所以基本上你把
$(this).css(“溢出”,“可见”)代码>进入回调?(很抱歉,直到今天我还不确定回调是什么)。@alexchenco回调只是一个每日函数。只有在定义的时间调用它。例如,当动画完成或ajax调用成功或失败时。您不能强制回调正常工作。它始终是您使用的API,它必须接受并调用给定的回调。
$(".user-review-toggle").toggle(function(){
$(this).css("backgroundPosition", "0 -12px");
$(this).prev('.user-review').animate({height: 150}, 200, function () {
$(this).css("overflow", "visible");
});
}, function(){
$(this).css("backgroundPosition", "0 0");
$(this).prev('.user-review').animate({height: 98}, 200, function () {
$(this).css("overflow", "hidden");
});
});