2012-07-24 65 views

回答

4

现在您正在使用“animate”和“fadeTo”,但您可以使用“animate”完成所有操作。换句话说,你可以用“animate”函数“动画”你的对象的多个属性。 因此,请使用:box.stop(true, true).delay(100).animate({top:-0, opacity: 0},150);

+0

这样的作品,非常感谢。我需要调查什么其他属性可以与动画结合。 – Andy 2012-07-24 16:57:45

+0

安迪,jQuery文档是你的朋友=) 请尝试在这里:http://api.jquery.com/animate/ 并请,请不要忘记标记其中一个答案是正确的吗? – rafaelbiten 2012-07-24 16:59:12

2

您可以更改元素的opacity

c.mouseenter(function(){ 
    box.stop(true, true).delay(100).animate({top:-0, opacity: 0}, 150) 
}) 
.mouseleave(function(){ 
    box.stop(true, true).delay(100).animate({top:40, opacity: 1}, 150) 
}); 
+0

感谢您的帮助。 – Andy 2012-07-24 16:57:59

+0

@欢迎您:) – undefined 2012-07-24 16:58:38

2

如果你打开CSS解决方案,您可以不用JS - http://jsfiddle.net/UpLts/2/

.blocks { 
    position: relative; 
    float: left; 
    margin: 20px; 
    width: 100px; 
    height: 100px; 
    border: 1px dotted #333; 
    overflow: hidden; 
} 

.blocks_title { 
    position: relative; 
    width: 20px; 
    height: 20px; 
    top: 40px; 
    left: 40px; 
    background: #333; 
    opacity: 1; 
    -webkit-transition: all .25s; 
     -moz-transition: all .25s; 
      transition: all .25s; 
} 

.blocks:hover .blocks_title { 
    top: 0; 
    opacity: 0; 
} 
+0

优秀。我传统上使用jQuery来制作动画,但CSS看起来更像是要走的路。谢谢。 – Andy 2012-07-24 17:42:31

+0

@Andy请记住,如果这是一个问题,这个CSS3 awesomeness将无法在较旧的IE-s中工作 – 2012-07-24 17:44:15

+0

感谢提醒我:) – Andy 2012-07-24 17:55:52