我正在尝试停止fadeTo()动画。我有4张图片,其中3张(未悬停的)应该变暗,而悬停的图片保持不透明为1。不幸的是,到目前为止,我的代码使每个图片,包括悬停的图片,在这个图片再次“亮起”之前都变暗了。相反,我只希望它在第一个实例中保持在100%,因为其他一切都会使网站看起来没有响应。
到目前为止,我所拥有的是:
$("#submenu").load("submenu.html", function(){
function darken(){;
$("#submenu li").find("img").fadeTo( 100, 0.20 );
}
function brighten(){
$("#submenu li").find("img").fadeTo( 100, 1.00 );
}
$('#submenu li').each(function(index) {
$(this).hover(
function () {
darken();
// $(this).stop(1,0).fadeTo(100, 0.20);
// if I do this ^ this image stays dark, even when hovered, and stays black when unhovered
// $(this).stop(1,0).fadeTo(100, 0.20);
// this ^ has no effect on the image whatsoever and it stays dark if I remove the line below
$(this).find("img").fadeTo( 100, 1.00 );
// keeping this ^ line, it shows the behavior as stated in the question
},
function () {
brighten ();
}
);
});我在stop()调用中使用了很多(true,false)语句,但到目前为止还没有任何成功的组合。
发布于 2015-07-07 22:37:46
好吧,我仍然对web dev一无所知(我是一个应用程序开发人员),但我现在所做的是将元素传递给darken()方法,这样它就知道什么是“不能”darken了。将在稍后清理代码时发布代码。
$("#submenu").load("submenu.html", function(){
function darken(topkek){
$.each($('#submenu ul li'), function( index, value ) {
if(topkek.innerHTML!=$(this).html()){
$(this).find("img").stop(true).fadeTo( 100, 0.40 );
}
// I think one couldn't have done this worse than here but if it look stupid and it work, it ain't stupid
});
}
function brighten(){
$("#submenu li").find("img").stop(true).fadeTo( 450, 1.00 );
}
$('#submenu li').each(function(index) {
$(this).hover(
function () {
darken(this);
},
function () {
brighten ();
}
);
});
});https://stackoverflow.com/questions/31264379
复制相似问题