学习JQuery - 12
来源:互联网 发布:淘宝客资源怎么找 编辑:程序博客网 时间:2024/04/29 01:29
3. 建立自定义的动画
我们把“显示/隐藏”按照时序排列就是动画了!
jQuery提供了一个强大的方法:animate()
我们今天主要讲使用2个参数时实现的效果。
.animate({properties},duration);在使用前,我们来重温一下:box-model
因为在.animate()的properties中有许多关于他们的设置
1)backgroundPosition2)borderLeft3)borderLeftWidth4)borderRight5)borderRightWidth6)borderSpacing7)borderTop8)borderTopWidth9)borderWidth10)bottom11)fontSize12)left13)marginBottom14)marginLeft15)marginRight16)marginTop17)paddingBottom18)paddingLeft19)paddingRight20)paddingTop21)position22)right23)top
还有三个经常使用的:height、width、opacity;这三个属性大部分使用“toggle”值以达到动画效果。
第二个参数是期间设定(在多长的时间内完成),单位为毫秒(ms)。
当我们隐藏内容时,显示“read more”链接;
但我们显示内容时,显示“read less”链接;
js代码
var $firstPara = $('p').eq(1);$firstPara.hide();$('a.more').click(function(e) { e.preventDefault();$firstPara.animate({height: 'toggle'}, 500);var $link = $(this);if ($link.text() == 'read more') {$link.text('read less');}else {$link.text('read more');} });点击“read more”(显示第一行时的图片)
完成时的效果
Abraham Lincoln's Gettysburg Address
Fourscore and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal.
Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field as a final resting-place for those who here gave their lives that the nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate, we cannot hallow, this ground.
read lessThe brave men, living and dead, who struggled here have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember, what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced.
It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom and that government of the people, by the people, for the people, shall not perish from the earth.
完成时的效果
Abraham Lincoln's Gettysburg Address
Fourscore and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal.
read moreThe brave men, living and dead, who struggled here have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember, what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced.
It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom and that government of the people, by the people, for the people, shall not perish from the earth.
我们增加“模糊”和“字体”属性
js代码
$firstPara.animate({height: 'toggle', opacity: 'toggle', fontSize: '16px'}, 500);效果1(点击“read more”):
P-3 显示第二行时
效果2(点击“read less”):
P-4 未隐藏第二行
附:
chapter4-2.html(详见《学习JQuery - 11》)
chapter04.css(详见《学习JQuery - 11》)
chpater04-3.js
$(document).ready(function() { var $firstPara = $('p').eq(1);$firstPara.hide();$('a.more').click(function(e) { e.preventDefault();$firstPara.animate({height: 'toggle', opacity: 'toggle', fontSize: '16px'}, 2000);var $link = $(this);if ($link.text() == 'read more') {$link.text('read less');}else {$link.text('read more');} });});
- 学习JQuery - 12
- JavaScript学习 jquery学习12 键盘事件
- 学习jquery-Jquery基础知识
- jquery学习--jQuery安装
- jQuery学习--jQuery选择器
- 学习JQuery
- jquery 学习
- JQuery 学习
- jquery 学习
- jQuery学习
- 学习JQuery
- jquery 学习
- jquery学习
- 学习jquery
- Jquery 学习
- JQuery 学习
- Jquery学习
- jquery 学习
- 2013我在奔波中走过-----------那年的高考改变了我们什么?
- Hadoop分布式文件系统:架构和设计(摘自Hadoop官方文档)
- 安装教程-Mysql
- bzoj 1004: [HNOI2008]Cards
- 学习jQuery必须知道的几种常用方法
- 学习JQuery - 12
- WM_DRAWITEM与DrawItem()的讨论
- bzoj 1005: [HNOI2008]明明的烦恼
- nyoj325zb的生日(基础搜索题目)
- String相关的操作
- bzoj 1491[NOI 2007]社交网络
- bzoj1503 郁闷的出纳员
- UNIX 处理目标文件的工具
- daliu_IT学习Android笔记第二篇--android(安卓)开发有前(钱)途吗?