JQuery Slider 不流畅,写错了?
因此,在我不懈努力以更好地使用 JQuery 的过程中,我构建了这个水平滑块。这个想法是,当悬停时,div 标签会展开,并且它的文本不透明度变得可见。其他 div 标签的标题会淡出。
看起来效果不错,但动画似乎有点不稳定。我将整个背景设为绿色,这样您就可以在右侧看到它的宽度如何不时变化。
有没有更好
的方法这还是我只是让动画过度紧张?
$(function() {
$("#one").hover(
function() {
$("#two, #three, #four, #five").stop().animate({width: 50, }, 1000);
$("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blockone").stop().animate({opacity:1.0}, 1500);
$("#one").stop().animate({width:700, }, 1000);
},
function() {
$("#two, #three, #four, #five").stop().animate({width: 180, opacity:1.0 }, 1000);
$("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blockone").stop().animate({opacity:0.0}, 500);
$("#one").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#two").hover(
function() {
$("#one, #three, #four, #five").stop().animate({width: 50 }, 1000);
$("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blocktwo").stop().animate({opacity:1.0}, 1500);
$("#two").stop().animate({width:700 }, 1000);
},
function() {
$("#one, #three, #four, #five").stop().animate({width: 180 }, 1000);
$("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blocktwo").stop().animate({opacity:0.0}, 500);
$("#two").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#three").hover(
function() {
$("#two, #one, #four, #five").stop().animate({width: 50 }, 1000);
$("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blockthree").stop().animate({opacity:1.0}, 1500);
$("#three").stop().animate({width:700 }, 1000);
},
function() {
$("#two, #one, #four, #five").stop().animate({width: 180 }, 1000);
$("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blockthree").stop().animate({opacity:0.0}, 500);
$("#three").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#four").hover(
function() {
$("#two, #three, #one, #five").stop().animate({width: 50 }, 1000);
$("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blockfour").stop().animate({opacity:1.0}, 1500);
$("#four").stop().animate({width:700 }, 1000);
},
function() {
$("#two, #three, #one, #five").stop().animate({width: 180 }, 1000);
$("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blockfour").stop().animate({opacity:0.0}, 500);
$("#four").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#five").hover(
function() {
$("#two, #three, #four, #one").stop().animate({width: 50 }, 1000);
$("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:0.0}, 500);
$("#blockfive").stop().animate({opacity:1.0}, 1500);
$("#five").stop().animate({width:700 }, 1000);
},
function() {
$("#two, #three, #four, #one").stop().animate({width: 180 }, 1000);
$("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:1.0}, 1000);
$("#blockfive").stop().animate({opacity:0.0}, 500);
$("#five").stop().animate({width: 180 }, 1000);
}
);
});
So in my tireless effort to get better with JQuery, I built this horizontal slider. The idea is, when hovered, a div tag expands and it's text opacity becomes visible. The other div tags' titles are meant to fade out.
It seems to work ok, but the animation seems a little choppy. I made the entire background green so you can see on the right how it varies in width from time to time.
http://s354510196.onlinehome.us/TEMPDUMP/JQuerySlider/
Is there a better method for this or am I simply straining the animation too much?
$(function() {
$("#one").hover(
function() {
$("#two, #three, #four, #five").stop().animate({width: 50, }, 1000);
$("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blockone").stop().animate({opacity:1.0}, 1500);
$("#one").stop().animate({width:700, }, 1000);
},
function() {
$("#two, #three, #four, #five").stop().animate({width: 180, opacity:1.0 }, 1000);
$("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blockone").stop().animate({opacity:0.0}, 500);
$("#one").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#two").hover(
function() {
$("#one, #three, #four, #five").stop().animate({width: 50 }, 1000);
$("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blocktwo").stop().animate({opacity:1.0}, 1500);
$("#two").stop().animate({width:700 }, 1000);
},
function() {
$("#one, #three, #four, #five").stop().animate({width: 180 }, 1000);
$("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blocktwo").stop().animate({opacity:0.0}, 500);
$("#two").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#three").hover(
function() {
$("#two, #one, #four, #five").stop().animate({width: 50 }, 1000);
$("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blockthree").stop().animate({opacity:1.0}, 1500);
$("#three").stop().animate({width:700 }, 1000);
},
function() {
$("#two, #one, #four, #five").stop().animate({width: 180 }, 1000);
$("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blockthree").stop().animate({opacity:0.0}, 500);
$("#three").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#four").hover(
function() {
$("#two, #three, #one, #five").stop().animate({width: 50 }, 1000);
$("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:0.0}, 500);
$("#blockfour").stop().animate({opacity:1.0}, 1500);
$("#four").stop().animate({width:700 }, 1000);
},
function() {
$("#two, #three, #one, #five").stop().animate({width: 180 }, 1000);
$("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:1.0}, 1000);
$("#blockfour").stop().animate({opacity:0.0}, 500);
$("#four").stop().animate({width: 180 }, 1000);
}
);
});
$(function() {
$("#five").hover(
function() {
$("#two, #three, #four, #one").stop().animate({width: 50 }, 1000);
$("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:0.0}, 500);
$("#blockfive").stop().animate({opacity:1.0}, 1500);
$("#five").stop().animate({width:700 }, 1000);
},
function() {
$("#two, #three, #four, #one").stop().animate({width: 180 }, 1000);
$("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:1.0}, 1000);
$("#blockfive").stop().animate({opacity:0.0}, 500);
$("#five").stop().animate({width: 180 }, 1000);
}
);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜四个并行的停止/动画没有帮助。
顺便说一下,你可以像这样重写整个块,但这不会改变性能
the four parrallel stop/animate do not help I guess.
by the way you can rewrite the full block like this, but it won't change performance