jQuery1.9(动画效果)学习之—— .fadeIn( [duration ] [, complete ] )

 

描述: 通过淡入的方式显示匹配元素。

 

.fadeIn( [duration ] [, complete ] )

 

  • duration (默认: 400)
    类型: Number or String
    一个字符串或者数字决定动画将运行多久。
  • complete
    类型: Function()
    在动画完成时执行的函数。
.fadeIn( options )
  • options
    类型: PlainObject
    一组包含动画选项的值的集合。 支持的选项:
    • duration (default: 400)
      Type: Number or String
      一个字符串或者数字决定动画将运行多久。(愚人码头注:默认值: "normal", 三种预定速度的字符串("slow", "normal", 或 "fast")或表示动画时长的毫秒数值(如:1000) )
    • easing (default: swing)
      Type: String
      一个字符串,表示过渡使用哪种缓动函数。(愚人码头注:jQuery自身提供"linear" 和 "swing",其他效果可以使用 jQuery Easing Plugin插件)
    • queue (default: true)
      Type: Boolean or String
      一个布尔值,指示是否将动画放置在效果队列中。如果为false时,将立即开始动画。 从jQuery1.7开始,队列选项也可以接受一个字符串,在这种情况下,在动画被添加到由该字符串表示的队列中。当一个自定义的队列名称被使用,动画不会自动启动;你必须调用 .dequeue("queuename")来启动它。
    • specialEasing
      Type: PlainObject
      一组一个或多个通过相应的参数和相对简单函数定义的CSS属性 ( 1.4 新增)
    • step
      Type: Function( Number now, Tween tween )
      每个动画元素的每个动画属性将调用的函数。这个函数为修改Tween 对象提供了一个机会来改变设置中得属性值。
    • progress
      Type: Function( Promise animation, Number progress, Number remainingMs )
      每一步动画完成后调用的一个函数,无论动画属性有多少,每个动画元素都执行单独的函数。 (version added: 1.8)
    • complete
      Type: Function()
      在动画完成时执行的函数。
    • done
      Type: Function( Promise animation, Boolean jumpedToEnd )
      在动画完成时执行的函数。 (他的Promise对象状态已完成). (version added: 1.8)
    • fail
      Type: Function( Promise animation, Boolean jumpedToEnd )
      动画失败完成时执行的函数。(他的Promise对象状态未完成)。 (version added: 1.8)
    • always
      Type: Function( Promise animation, Boolean jumpedToEnd )
      在动画完成或未完成情况下停止时执行的函数。(他的Promise对象状态已完成或未完成)。 (version added: 1.8)

     

.fadeIn( [duration ] [, easing ] [, complete ] )

 

  • duration (默认: 400)
    类型: Number or String
    一个字符串或者数字决定动画将运行多久。
  • easing (默认: swing)
    类型: String
    一个字符串,表示过渡使用哪种缓动函数。(译者注:jQuery自身提供"linear" 和 "swing",其他可以使用相关的插件)
  • complete
    类型: Function()
    在动画完成时执行的函数。

 

.fadeIn()方法通过匹配元素的不透明度做动画效果。这是一个和.fadeTo()类似的方法,但那个方法不会隐藏的元素并可以指定最后的透明度值。

 

duration(延时时间)参数是以毫秒为单位的,数值越大,动画越慢,不是越快。字符串 'fast''slow' 分别代表200和600毫秒的延时。如果提供任何其他字符串,或者这个duration参数被省略,那么默认使用400毫秒的延时

 

我们可以给任何元素做动画,比如一个简单的图片:

<div id="clickme">
Click here
</div>
<img id="book" src="book.png" alt="" width="100" height="123" />
With the element initially hidden, we can show it slowly:
$('#clickme').click(function() {
$('#book').fadeIn('slow', function() {
// Animation complete
});
});

 

Easing(缓冲函数)

从jQuery 1.4.3开始,增加了一个字符串命名的可选的参数,用于确定使用的缓动函数。一个缓动函数指定用于动画进行中在不同点位的速度。 在jQuery库中easing默认的是调用 swing, 如果想要在一个恒定的速度进行动画,那么调用 linear. 更多的缓动函数要使用的插件,最显着的是jQuery UI suite(译者注:或jQuery Easing Plugin插件)。

Callback Function(回调函数)

如果提供回调函数,这个 callback 函数将在动画完成后被执行一次。这个能用来将不同的动画串联起来组成一个事件序列。这个回调函数不设置任何参数,但是this指向执行动画的DOM元素。如果多个元素一起做动画效果,值得注意的是这个回调函数在每个匹配元素上执行一次。这个动画不是作为一个整体。

从jQuery 1.6开始.promise()方法可以用来配合deferred.done() 方法作为一个整体,当所有匹配的元素已经完成各自的动画后,再执行一个回调的动画。 ( 查看 .promise() 例子 )。

Additional Notes:(其他注意事项:)

  • 所有jQuery效果,包括.fadeIn(),都能通过设置jQuery.fx.off = true全局的关闭,效果等同于持续时间设置为0。更多信息查看 jQuery.fx.off.

 

例子:

Example: 淡出所有段落,在600毫秒内完成这些动画。
<!DOCTYPE html>
<html>
<head>
<style>
span { color:red; cursor:pointer; }
div { margin:3px; width:80px; display:none;
height:80px; float:left; }
div#one { background:#f00; }
div#two { background:#0f0; }
div#three { background:#00f; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<span>Click here...</span>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<script>
$(document.body).click(function () {
$("div:hidden:first").fadeIn("slow");
});
</script>
</body>
</html>

 

 

Example: Fades a red block in over the text. Once the animation is done, it quickly fades in more text on top.
<!DOCTYPE html>
<html>
<head>
<style>
p { position:relative; width:400px; height:90px; }
div { position:absolute; width:400px; height:65px;
font-size:36px; text-align:center;
color:yellow; background:red;
padding-top:25px;
top:0; left:0; display:none; }
span { display:none; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p>
Let it be known that the party of the first part
and the party of the second part are henceforth
and hereto directed to assess the allegations
for factual correctness... (<a href="#">click!</a>)
<div><span>CENSORED!</span></div>
</p>
<script>
$("a").click(function () {
$("div").fadeIn(3000, function () {
$("span").fadeIn(100);
});
return false;
});
</script>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值