html5怎么设置网页过渡效果

html5怎么设置网页过渡效果,第1张

步骤1 创建空白的HTML 5模版

首先,我们创建一个空白的模版,代码很简单,如下所示:

复制代码

步骤2 增加HTML 5新标签 HTML 5中新增加了不少标签,如:

article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section

在页面模版中,我们需要确保每个区域都能正确地对齐,因此需要使用HEADER、 NAVIGATION、 CONTENT、 SIDEBAR和Footer这些标签。代码如下所示:

复制代码

读者可能留意到这里使用的div id=”wrapper”,这个是稍候用来做meida query的时候调整全局CSS样式调整用的 步骤3 往HTML 5标签中增加代码

1)首先往标题中增加如下代码:

 Simple HTML5 Template

复制代码

2)往导航标签中添加如下代码,这样很方便地构件了一个简单的页面分类导航:

Home About Parent Page Child

One Child Two with child Child One Child

Two Child Three Child Three

Contact

复制代码

3)使用标签来描述每一个要展示的内容实体,比如要展示的是多篇文章列表,其中的每一篇文章的具体内容就可以使用标签了。如下代码所示:

This is a title for post

Richard KS 20th March 2013 Tutorials HTML5, CSS3

and Responsive 10 Comments Lorem

Ipsum is simply dummy text of the printing and typesetting industry.

Lorem Ipsum has been the industry's standard dummy text ever since the

1500s

复制代码

4)添加标签 HTML5提供的元素标签用来表示当前页面或文章的附属信息部分,可以包含与当前页面或主要内容相关的引用、侧边栏、广告、nav元素组,以及其他类似的有别与主要内容的部分。

根据目前的规范,元素有两种使用方法:

被包含在中作为主要内容的附属信息部分,其中的内容可以是与当前文章有关的引用、词汇列表等。

在之外使用,作为页面或站点全局的附属信息部分;最典型的形式是侧边栏(sidebar),其中的内容可以是友情链接、附属导航或广告单元等。

代码如下:

Categories Category 1 Category 2

Parent Category Child One Child Two

Grandchild One Grandchild Two Grandchild Three

Child Three Category 3

Text Lorem Ipsum is simply dummy

text of the printing and typesetting industry.

复制代码

5)加上最后的标签,代码为:

Copyright@ 2013 HTML5.com Privacy Policy - About Us

复制代码

步骤4 增加CSS样式

首先创建一个空白的样式,如下:

[/code] 然后在http://necolas.github.com/normalize.css/中下载这个css,然后将其内容复制到该空白的文件中代码如下: [code]body {

font-family: arial, sans-serif

font-size: 100%/* best for all browser using em */

padding:0

margin:0

}

*, html { line-height: 1.6em}

article img { width:automax-width:100%height:auto}

.sidebar a, article a, header a, footer a { color: #C30}

header a { text-decoration: none}

#wrapper {

font-size: 0.8em/* 13px from 100% global font-size */

max-width: 960px/* standard 1024px wide */

margin: 0 auto

}

/* css for */

header { padding: 1em 0margin: 0pxfloat: leftwidth: 100%

}

header hgroup { width: 100%font-weight:normal}

/* css for */

nav

{ display: blockmargin: 0 0 2empadding: 0px

float: leftwidth: 100%background-color: #181919

}

nav ul ul {display: none}

nav ul li:hover >ul {display: block}

nav

ul { padding: 0list-style: noneposition:

relativedisplay: inline-tablez-index: 9999

margin: 0pxfloat: leftwidth: 100%

}

nav ul:after {content: ""clear: bothdisplay: block}

nav ul li {float: left}

nav ul li:hover a {color: #fff}

nav

ul li a { display: blockpadding: 1emfont-size:

1.125emcolor: #ccctext-decoration: none

margin: 0pxbackground-color: #000border-right: 1px

solid #333

}

nav ul li:last-of-type a {border-right: 1px solid transparent !important}

nav

ul ul { background: #5f6975border-radius: 0px

padding: 0position: absolutetop: 100%width:

autofloat: none

}

nav ul li:hover { background: #5f6975color: #FFF

}

nav ul ul li a:hover { background-color: #4b545f

}

nav ul ul li {

float: none

border-bottom: 1px solid #444240

position: relative

}

nav ul ul li a {

padding: 0.5em 1em

font-size: 1em

width:10em

color: #fff

}

nav ul ul ul {

position: absoluteleft: 100%top:0

}

/* css for */

section.content { width: 70%float:left}

.content article { width:100%float:leftpadding: 0 0 1emmargin: 0 0 1emborder-bottom: 1px solid #ddd}

article .entry { clear:bothpadding: 0 0 1em}

h1.post-title { font-size: 1.8emmargin:0padding:0}

.entry.post-meta { color: #888}

.entry.post-meta span { padding: 0 1em 0 0}

.entry.post-content { font-size: 1.125emmargin:0padding:0}

/* css for */

aside.sidebar { width: 25%float:right}

aside.sidebar ul { width:100%margin: 0pxpadding: 0pxfloat: leftlist-style: none

}

aside.sidebar

ul li { width:100%margin: 0px 0px 2empadding:

0pxfloat: leftlist-style: none

}

aside.sidebar ul li ul li { margin: 0px 0px 0.2empadding: 0px

}

aside.sidebar

ul li ul li ul li { margin: 0pxpadding: 0px 0px 0px

1emwidth: 90%font-size: 0.9em

}

aside.sidebar

ul li h3.widget-title { width:100%margin: 0px

padding: 0pxfloat: leftfont-size: 1.45em

}

/* css for */

footer { width: 98%float:leftpadding: 1%background-color: whitemargin-top: 2em

}

footer .footer-left { width: 45%float:lefttext-align:left}

footer .footer-right { width: 45%float:righttext-align:right}

复制代码

步骤5 为移动应用使用@media query查询 为了进行响应式设计,最佳的方案是使用@media query去进行查询,在上面的CSS代码中添加如下代码:

/* ipad 768px */

@media only screen and (min-width:470px) and (max-width:770px){

body { background-color: red} #wrapper { width:96%font-size: 0.6875em}

section.content, aside.sidebar { width:100%}

}

/* iphone 468px */

@media only screen and (min-width:270px) and (max-width:470px){

body { background-color: yellow} #wrapper { width:96%font-size: 0.6875em}

section.content, aside.sidebar { width:100%}

}

复制代码

步骤6 增加jquery,modernizer和html5shiv到标签中 这里推荐使用Modernizr 和html5shiv,它们都是一个能在多种浏览器中通过运行各种脚本兼容运行支持大部分HTML 5标签的插件。我们将它们和jQuery库放在标签前

HTML5的诞生给web前端界带来了不小轰动,像什么动画旋转、图片滑块、图片轮播等等这些3D特效,也引发了不少朋友想要学习HTML5的好奇心。最近我一直在做canvas动画效果,发现canvas这个东西做动画不是不可以。相对于flash,它太底层。如果有给力的编辑器或者给力的框架的话,它就能发挥出更大的威力。

于是决定自己写一个简单一点的动画框架,以便能更方便地构建出一些动画效果。

我将分几个章节来讲述我这个小动画框架的实现:

1.通用类的提取:动画对象与帧对象

2.灵与肉的结合:便于拆卸的运动方程

3.进度条的实现:canvas的图片预加载

4.demo测试:通过一个demo测试框架

这一节我们先来说说通用类的提取。

其实上一篇文章我已经用到了这种从flash借鉴来的思路:一个动画对象(类似flash中的元件),一个帧对象(类似flash中的帧)。动画就是在不断在当前帧上绘制每个动画对象来实现的。有了这两个对象,再加上一些运动方法,我们就可以构建出动画来。

首先我们先来看看动画对象Aniele:

/*

*Aniele动画对象

*所有动画对象的始祖

*/

varAniele=function(){

this.img=newImage()

//定义动画对象位置

this.loca={

x:300,

y:300

}

//定义动画对象的大小(可以实现缩放)

this.dw

this.dh

//动画对象的速度属性

this.speed={

x:0,

y:0

}

//设置对象的透明度

this.alpha=1

//设置图像翻转,1为不翻转,-1为翻转

this.scale={

x:1,

y:1

}

//定动画对象的运动方法库

this.motionFncs=[]

}

Aniele.prototype={

//添加运动方法

addMotionFnc:function(name,fnc) {

this.motionFncs[name]=fnc

},

//删除运动方法

deleMotionFnc:function(name){

this.motionFncs[name]=null

},

//遍历运动方法库里的所有运动方法

countMotionFncs:function() {

for(vari=0i

if(this.motionFncs[i]==null)

continue

this.motionFncs[i].call(this)

}

},

//把自己绘制出来的方法,包括功能:水平翻转

draw:function(canvas,ctx){

//存储canvas状态ctx.save()

//实现透明度的改变

ctx.globalAlpha=this.alpha

//实现水平竖直翻转,定义drawImage的两个位置参数dx,dy

vardx=this.loca.x

vardy=this.loca.y

if(this.scale.x!=1||this.scale.y!=1){

if(this.scale.x<0){

console.log(this.img.width)

dx=canvas.width-this.loca.x-this.img.width

ctx.translate(canvas.width,1)

ctx.scale(this.scale.x,1)

}

if(this.scale.y<0){

dy=canvas.height-this.loca.y-this.img.height

ctx.translate(1,canvas.height)

ctx.scale(1,this.scale.y)

}

}

if(this.dw==null)

this.dw=this.img.width

if(this.dh==null)

this.dh=this.img.height

//画出对象

ctx.drawImage(this.img,dx,dy,this.dw,this.dh)

//恢复canvas状态ctx.restore()

}

}

动画对象的主要属性:

this.img=newImage()我们引入一张图片,依附在动画对象上;

this.loca.x等等图片的大小位置透明度等等,便于绘图时调用;

this.motionFncs=[]这个比较关键,我们给动画对象定义一个运动方法库,把动画对象的运动规则都放在这个运动方法库中统一管理(每个动画对象都有自己的运动方法库);

动画对象的主要方法:

addMotionFnc: 为动画对象的运动方法库中添加一个运动方法;

deleMotionFnc:为动画对象的运动方法库中删除一个运动方法;

countMotionFncs:为动画对象遍历运动方法库中的所有运动方法;

draw:把动画对象画在画布上,这里我们会把画布作为参数传到这个方法里面去,便于绘图;

在draw方法里,我封装了一些对图像的简单 *** 作,这些 *** 作在动画中会经常用到:透明,缩放和翻转。

有了这个,我们就好似获得了flash里的一个元件,我们可以通过修改它的属性来随意改变它。

那么帧对象呢?

帧对象肩负着渲染的任务,并且管理所有动画对象:

/*

*Render渲染对象

*管理所有动画对象和渲染

*参数:画布对象,画布上下文*/varRender=function(canvas,ctx) {

//引入画布

this.canvas=canvas

this.ctx=ctx

//创建一个缓冲画布

this.backBuffer=document.('canvas')

this.backBuffer.width=this.canvas.width

this.backBuffer.height=this.canvas.height

this.backBufferctx=this.backBuffer.getContext('2d')

//所有动画对象

this.aniEles=[]

}

Render.prototype={

//初始化画布int

int:function() {

clearInterval(this.sint)

this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)

this.backBufferctx.clearRect(0,0,this.backBuffer.width,this.backBuffer.height)

},

//设置开始渲染

begin:function() {

this.lastFrame=(newDate()).getTime()

this.sint=setInterval((function(progra){

returnfunction(){progra.render()}

})(this),SECOND)

},

//主渲染方法

render:function() {

//在画布和缓存画布上清除历史帧

this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height)

this.backBufferctx.clearRect(0,0,this.backBuffer.width,this.backBuffer.height)

//保存当前的实时输出帧率this.ftp

this.nowFrame=(newDate()).getTime()

this.ftp=1000/(this.nowFrame-this.lastFrame)

this.lastFrame=this.nowFrame

//调用每个动画对象的运动方法

for(vari=0i

if(this.aniEles[i]==null)

continue

this.aniEles[i].countMotionFncs()

//把对象绘制到后台缓冲画布上

this.aniEles[i].draw(this.backBuffer,this.backBufferctx)

}

//把后台对象绘制到前台

this.ctx.drawImage(this.backBuffer,0,0)

},

//增加动画对象

addAniEle:function(name,aniEle) {

this.aniEles[name]=aniEle

},

//删除动画对象

deleAniEle:function(name) {

this.aniEles[name]=null

}

}

帧对象的主要属性:

this.aniEles=[]用来存储当前画布上所有动画实例的数组;

大家用过canvas载入图片的应该知道,由于图片的异步载入,动画过程中图片会出现闪烁的现象,为了避免这种现象,我采用了双缓冲。

首先后台创建一个画布:

this.backBuffer=document.('canvas')

this.backBuffer.width=this.canvas.width

this.backBuffer.height=this.canvas.height

this.backBufferctx=this.backBuffer.getContext('2d')

我们所有绘制命令都执行在这个后台画布上,最后把后台画布画在前台画布上:

this.ctx.drawImage(this.backBuffer,0,0)

这种先把图绘在后台画布,再把后台画布复制到前台的方法就叫做双缓冲技术。

帧属性的主要方法:

int:用于初始化画布;

begin:开始动画渲染的方法;

render:主渲染的方法;

addAniEle:为当前帧添加动画对象;

deleAniEle:为当前帧删除动画;

我们利用帧对象的流程是:先为当前帧添加动画对象,然后让当前帧开始渲染。

河南新华电脑学院网络运营协会为您解答


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/8370739.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-15
下一篇2023-04-15

发表评论

登录后才能评论

评论列表(0条)

    保存