【发布时间】:2012-11-09 11:34:25
【问题描述】:
当mouseEnter 是一个图形时,我正在开发一个带有活动类.slider-active 的jQuery 滑块。
通过这种方式,我想以很酷的效果为我的.slider-imgcontainer 和我的 figcaption 制作动画:
当.slideractive改变时,前一个对象必须将.slider-imgcontainer的宽度减小到250px,并且在figcaption的width和padding之后减小到0。当我减小width的figcaption,文字太高了,所以我只用.hide和.show来纠正这个问题。
然后滑块开始工作,但是......当鼠标滚过多个图形时,它们都被动画化了。我已尝试纠正此问题,但找不到任何解决方案(使用 .clearQueue() et .stop())。
主要动画代码:
$(document).ready(function(){
var GLOBAL = {
window:$(window),
slider:$('.slider-work'),
container:$('#container'),
figure:$("figure")
}
/********* SLIDER MAIN *************/
// INIT LARGEUR ---
GLOBAL.slider.width($(".slider-work img").size() * 250 + 900);
// save width of figcaption in attr to animate them after (no auto animate)
GLOBAL.slider.find("figcaption").each(function(i) {
var t = $(this);
if(!t.parent().hasClass("slider-active"))
t.hide();
t.attr("largeur", t.width());
});
// hover
GLOBAL.slider.children("figure").mouseenter( function () {
var oldActive = $(".slider-active");
var thiss = $(this);
oldActive.removeClass("slider-active");
thiss.addClass("slider-active");
oldActive.find("figcaption").animate({
width: 0,
padding: 0
}, 220, 'linear', function() {
oldActive.find(".slider-imgcontainer").animate({
width : 250
}, 400, 'linear', function() {
// Animation de l'ancien active fini , alors :
//$(".slider-imgcontainer").removeAttr("style");
thiss.removeAttr("style").children(".slider-imgcontainer").animate({
width : 400
}, 400, 'linear', function(){
var largeurFigcaption = thiss.find("figcaption").show().attr("largeur");
thiss.find("figcaption").animate({
width : largeurFigcaption,
padding : " 0 20px 20px 20px"
}, 220, 'linear', function(){
});
});
});
});
});
// END MouseEnter
//End ready
});
还有我调试滑块的代码
GLOBAL.slider.children("figure").mouseout( function () {
var thiss = $(this);
//$("#title span").append(" toto");
var myChildrenBehave = GLOBAL.slider.filter(function() {
var filtered = $(this).children().is(":animated");
return filtered;
});
myChildrenBehave.clearQueue().stop();
});
我接受所有想法:)
【问题讨论】:
标签: jquery jquery-animate mouseenter mouseleave animated