主要思想:
10余年的交城網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。全網(wǎng)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整交城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“交城網(wǎng)站設(shè)計”,“交城網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
首先要準(zhǔn)備一張有連續(xù)幀的圖片,然后利用HTML5 Canvas的draw方法在不同的時間間隔繪制不同的幀,這樣看起來就像動畫在播放。
關(guān)鍵技術(shù)點:
JavaScript 函數(shù)setTimeout()有兩個參數(shù),第一個是參數(shù)可以傳遞一個JavaScript方法,
另外一個參數(shù)代表間隔時間,單位為毫秒數(shù)。代碼示例:
setTimeout( update, 1000/30);
Canvas的API-drawImage()方法,需要指定全部9個參數(shù):
ctx.drawImage(myImage, offw, offh, width,height, x2, y2, width, height);
其中offw, offh是指源圖像的起始坐標(biāo)點,width, height表示源圖像的寬與高,x2,y2表
示源圖像在目標(biāo)Canvas上的起始坐標(biāo)點。
!DOCTYPE?html?
html?
head?
meta?http-equiv="X-UA-Compatible"?content="chrome=IE8"?
meta?http-equiv="Content-type"?content="text/html;charset=UTF-8"?
titleCanvas?Mouse?Event?Demo/title?
link?href="default.css"?rel="stylesheet"?/?
script?
var?ctx?=?null;?//?global?variable?2d?context?
var?started?=?false;?
var?mText_canvas?=?null;?
var?x?=?0,?y?=0;?
var?frame?=?0;?//?22?5*5?+?2?
var?imageReady?=?false;?
var?myImage?=?null;?
var?px?=?300;?
var?py?=?300;?
var?x2?=?300;?
var?y2?=?0;?
window.onload?=?function()?{?
var?canvas?=?document.getElementById("animation_canvas");?
console.log(canvas.parentNode.clientWidth);?
canvas.width?=?canvas.parentNode.clientWidth;?
canvas.height?=?canvas.parentNode.clientHeight;?
if?(!canvas.getContext)?{?
console.log("Canvas?not?supported.?Please?install?a?HTML5?compatible?browser.");?
return;?
}?
//?get?2D?context?of?canvas?and?draw?rectangel?
ctx?=?canvas.getContext("2d");?
ctx.fillStyle="black";?
ctx.fillRect(0,?0,?canvas.width,?canvas.height);?
myImage?=?document.createElement('img');?
myImage.src?=?"../robin.png";?
myImage.onload?=?loaded();?
}?
function?loaded()?{?
imageReady?=?true;?
setTimeout(?update,?1000/30);?
}?
function?redraw()?{?
ctx.clearRect(0,?0,?460,?460)?
ctx.fillStyle="black";?
ctx.fillRect(0,?0,?460,?460);?
//?find?the?index?of?frames?in?image?
var?height?=?myImage.naturalHeight/5;?
var?width?=?myImage.naturalWidth/5;?
var?row?=?Math.floor(frame?/?5);?
var?col?=?frame?-?row?*?5;?
var?offw?=?col?*?width;?
var?offh?=?row?*?height;?
//?first?robin?
px?=?px?-?5;?
py?=?py?-?5;?
if(px??-50)?{?
px?=?300;?
}?
if(py??-50)?{?
py?=?300;?
}?
//var?rate?=?(frame+1)?/22;?
//var?rw?=?Math.floor(rate?*?width);?
//var?rh?=?Math.floor(rate?*?height);?
ctx.drawImage(myImage,?offw,?offh,?width,?height,?px,?py,?width,?height);?
//?second?robin?
x2?=?x2?-?5;?
y2?=?y2?+?5;?
if(x2??-50)?{?
x2?=?300;?
y2?=?0;?
}?
ctx.drawImage(myImage,?offw,?offh,?width,?height,?x2,?y2,?width,?height);?
}?
function?update()?{?
redraw();?
frame++;?
if?(frame?=?22)?frame?=?0;?
setTimeout(?update,?1000/30);?
}?
/script?
/head?
body?
h1HTML?Canvas?Animations?Demo?-?By?Gloomy?Fish/h1?
prePlay?Animations/pre?
div?id="my_painter"?
canvas?id="animation_canvas"/canvas?
/div?
/body?
/html
首先是HTML代碼,非常簡單,列出我們需要渲染的文字:
div?class="foo"
span?class="letter"?data-letter="A"A/span
span?class="letter"?data-letter="B"B/span
span?class="letter"?data-letter="C"C/span
span?class="letter"?data-letter="D"D/span
span?class="letter"?data-letter="E"E/span
span?class="letter"?data-letter="F"F/span
span?class="letter"?data-letter="G"G/span
span?class="letter"?data-letter="H"H/span
span?class="letter"?data-letter="I"I/span
span?class="letter"?data-letter="L"L/span
span?class="letter"?data-letter="M"M/span
span?class="letter"?data-letter="N"N/span
span?class="letter"?data-letter="O"O/span
span?class="letter"?data-letter="P"P/span
span?class="letter"?data-letter="Q"Q/span
span?class="letter"?data-letter="R"R/span
span?class="letter"?data-letter="S"S/span
span?class="letter"?data-letter="T"T/span
span?class="letter"?data-letter="U"U/span
span?class="letter"?data-letter="V"V/span
span?class="letter"?data-letter="Z"Z/span
/div
CSS3
.letter{
display:?inline-block;
font-weight:?900;
font-size:?8em;
margin:?0.2em;
position:?relative;
color:?#00B4F1;
transform-style:?preserve-3d;
perspective:?400;
z-index:?1;
}
這樣我們就讓這些字母安安靜靜的排列起來,并有了自己的背景顏色,等待強大的CSS3來渲染。
接下來我們要讓文字在鼠標(biāo)滑過的時候產(chǎn)生翻轉(zhuǎn)傾斜的動畫。
.letter:before,?.letter:after{
position:absolute;
content:?attr(data-letter);
transform-origin:?top?left;
top:0;
left:0;
}
.letter,?.letter:before,?.letter:after{
transition:?all?0.3s?ease-in-out;
}
.letter:before{
color:?#fff;
text-shadow:
-1px?0px?1px?rgba(255,255,255,.8),
1px?0px?1px?rgba(0,0,0,.8);
z-index:?3;
transform:
rotateX(0deg)
rotateY(-15deg)
rotateZ(0deg);
}
.letter:after{
color:?rgba(0,0,0,.11);
z-index:2;
transform:
scale(1.08,1)
rotateX(0deg)
rotateY(0deg)
rotateZ(0deg)
skew(0deg,1deg);
}
.letter:hover:before{
color:?#fafafa;
transform:
rotateX(0deg)
rotateY(-40deg)
rotateZ(0deg);
}
.letter:hover:after{
transform:
scale(1.08,1)
rotateX(0deg)
rotateY(40deg)
rotateZ(0deg)
skew(0deg,22deg);
}
主要思想:\x0d\x0a首先要準(zhǔn)備一張有連續(xù)幀的圖片,然后利用HTML5Canvas的draw方法在不同的時間間隔繪制不同的幀,這樣看起來就像動畫在播放。\x0d\x0a關(guān)鍵技術(shù)點:\x0d\x0aJavaScript函數(shù)setTimeout()有兩個參數(shù),第一個是參數(shù)可以傳遞一個JavaScript方法,\x0d\x0a另外一個參數(shù)代表間隔時間,單位為毫秒數(shù)。代碼示例:\x0d\x0asetTimeout(update,1000/30);\x0d\x0aCanvas的API-drawImage()方法,需要指定全部9個參數(shù):\x0d\x0actx.drawImage(myImage,offw,offh,width,height,x2,y2,width,height);\x0d\x0a其中offw,offh是指源圖像的起始坐標(biāo)點,width,height表示源圖像的寬與高,x2,y2表\x0d\x0a示源圖像在目標(biāo)Canvas上的起始坐標(biāo)點。\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0aCanvasMouseEventDemo\x0d\x0a\x0d\x0a\x0d\x0avarctx=null;globalvariable2dcontext\x0d\x0avarstarted=false;\x0d\x0avarmText_canvas=null;\x0d\x0avarx=0,y=0;\x0d\x0avarframe=0;225*5+2\x0d\x0avarimageReady=false;\x0d\x0avarmyImage=null;\x0d\x0avarpx=300;\x0d\x0avarpy=300;\x0d\x0avarx2=300;\x0d\x0avary2=0;\x0d\x0awindow.onload=function(){\x0d\x0avarcanvas=document.getElementById("animation_canvas");\x0d\x0aconsole.log(canvas.parentNode.clientWidth);\x0d\x0acanvas.width=canvas.parentNode.clientWidth;\x0d\x0acanvas.height=canvas.parentNode.clientHeight;\x0d\x0aif(!canvas.getContext){\x0d\x0aconsole.log("Canvasnotsupported.PleaseinstallaHTML5compatiblebrowser.");\x0d\x0areturn;\x0d\x0a}\x0d\x0aget2Dcontextofcanvasanddrawrectangel\x0d\x0actx=canvas.getContext("2d");\x0d\x0actx.fillStyle="black";\x0d\x0actx.fillRect(0,0,canvas.width,canvas.height);\x0d\x0amyImage=document.createElement('img');\x0d\x0amyImage.src="..robin.png";\x0d\x0amyImage.onload=loaded();\x0d\x0a}\x0d\x0afunctionloaded(){\x0d\x0aimageReady=true;\x0d\x0asetTimeout(update,100030);\x0d\x0a}\x0d\x0afunctionredraw(){\x0d\x0actx.clearRect(0,0,460,460)\x0d\x0actx.fillStyle="black";\x0d\x0actx.fillRect(0,0,460,460);\x0d\x0afindtheindexofframesinimage\x0d\x0avarheight=myImage.naturalHeight5;\x0d\x0avarwidth=myImage.naturalWidth5;\x0d\x0avarrow=Math.floor(frame5);\x0d\x0avarcol=frame-row*5;\x0d\x0avaroffw=col*width;\x0d\x0avaroffh=row*height;\x0d\x0afirstrobin\x0d\x0apx=px-5;\x0d\x0apy=py-5;\x0d\x0aif(px
HTML5手機上下滑動翻頁特效是一款手機移動端觸屏滑動效果實現(xiàn)完整代碼如下:
1、html5頁面代碼
!DOCTYPE html
htmlheadmeta http-equiv="Content-Type" content="text/html; charset=UTF-8"
titleHTML5手機頁面觸屏滑動上下翻頁特效/title
meta charset="utf-8"
meta name="apple-touch-fullscreen" content="YES"
meta name="format-detection" content="telephone=no"
meta name="apple-mobile-web-app-capable" content="yes"
meta name="apple-mobile-web-app-status-bar-style" content="black"
meta http-equiv="Expires" content="-1"
meta http-equiv="pragram" content="no-cache"
link rel="stylesheet" type="text/css" href="./hamer_files/main.css"
link rel="stylesheet" type="text/css" href="./hamer_files/endpic.css"
script type="text/javascript" src="./hamer_files/offline.js"/script
meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi"
/head
body class="s-bg-ddd pc no-3d perspective yes-3d" style="-webkit-user-select: none;"
section class="u-alert"
? img style="display:none;" src="./hamer_files/loading_large.gif"
? div class="alert-loading z-move"
? ? ? div class="cycleWrap" span class="cycle cycle-1"/span
? ? ? ? ? span class="cycle cycle-2"/spanspan class="cycle cycle-3"/spanspan class="cycle cycle-4"/span
? ? ? /div
? ? ? div class="lineWrap" span class="line line-1"/spanspan class="line line-2"/spanspan class="line line-3"/span
? ? ? /div
? /div
/section
section class="u-arrow"
? p class="css_sprite01"/p
/section
section class="p-ct transformNode-2d transformNode-3d" style="height: 918px;"
? div class="translate-back" style="height: 918px;"
? ? ? div class="m-page m-fengye" data-page-type="info_pic3" data-statics="info_pic3" style="height: 918px;"
? ? ? ? ? div class="page-con lazy-finish" data-position="50% 50%" data-size="cover" style="height: 920px; background-image: url(hamer_files/1.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/2.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/3.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/4.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/5.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/6.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/7.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? ? ? div class="m-page m-bigTxt f-hide" data-page-type="bigTxt" data-statics="info_list" style="height: 918px;"
? ? ? ? ? div class="page-con j-txtWrap lazy-finish" data-position="50% 50%" data-size="cover" style="background-image: url(hamer_files/8.jpg); background-size: cover; background-position: 50% 50%;"/div
? ? ? /div
? /div
/section
section class="u-pageLoading"
? img src="./hamer_files/load.gif" alt="loading"
/section
script src="./hamer_files/init.mix.js" type="text/javascript" charset="utf-8"/script
script src="./hamer_files/coffee.js" type="text/javascript" charset="utf-8"/script
script src="./hamer_files/99_main.js" type="text/javascript" charset="utf-8"/script
/body/html
2、css代碼:
@charset "utf-8";
.ad_foot li { margin:0 auto 1em; font-size:1.8em; padding:15px; background:#FFF;}
.ad_foot li a {display:block;}
.ad_foot li .l {width:75px; height:75px; float:left; overflow:hidden;}
.ad_foot li .l img {width:75px; width:75px;}
.ad_foot li .r {width:78%; float:left; margin-left:30px; color:#666; overflow:hidden;}
.ad_foot li .r p {color:#999; font-size:1.2em; }
.ad_foot li .r span {font-size:0.8em;}
.ad_foot li .r i {font-style:normal;}
.lazy-img, .lazy-finish{background-color:#f0eded;}
.page-list{font-size:20px;font-family: "Microsoft yahei";padding-left:17px;padding-top:30px;height:35px;border-bottom:1px solid #b5b5b5;display:none;}
.ad_foot{padding:15px 15px 0 15px;}
/*聲音播放按鈕*/
#song_img {width:293px; height:41px; display:block; position:absolute; right:4.1em; top:1.6em; font-size:1.7em; text-align:center; line-height:41px; color:#FFF; background:url(../img/music_c3.png) no-repeat 0 0;}
/*底部推薦*/
.ad_list{margin-top:2em;}.ad_list li {width:46%; background:none; padding:0; float:left;margin-bottom: 1em;}
.ad_list li.r {float:right;}.ad_list li a img {width:100%; height:auto;}
.ad_foot h3 {width:100%; height:48px; line-height:48px; background:#F9F5EC;}
.ad_foot h3 a {display:inline-block; color:#444; width:50%; text-align:center; font-size:1.5em; height:48px; border-bottom:2px solid #FF9240;}
.ad_foot h3 a.active {color:#FFF; background:#FF9240;}
.magazine_1 li {
width:100%;
margin-bottom: 1em;
font-size: 1.8em;
padding: 15px;
background: #FFF;}
.magazine_1 li a {display:block;}
.magazine_1 li .l {width: 75px;
height: 75px;
float: left;
overflow: hidden;}
.magazine_1 li .l img {width:75px; height:75px;}
.magazine_1 li .r {width: 78%;
float: left;
margin-left: 30px;
color: #666;
overflow: hidden;}
.magazine_1 li .r p {
color: #999;
font-size: 1.2em;
.magazine_1 li .r span {font-size:0.8em;}
.ad_foot li .r i {font-style:normal;}
3、運行效果如下: