版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第基于JS實(shí)現(xiàn)動(dòng)態(tài)跟隨特效的示例代碼目錄演示技術(shù)棧源碼css部分js部分
演示
技術(shù)棧
這次用到了關(guān)于css的一些功能,和jQuery。
CSS3中添加的新屬性animation是用來(lái)為元素實(shí)現(xiàn)動(dòng)畫(huà)效果的,但是animation無(wú)法單獨(dú)擔(dān)當(dāng)起實(shí)現(xiàn)動(dòng)畫(huà)的效果。承載動(dòng)畫(huà)的另一個(gè)屬性@keyframes。使用的時(shí)候?yàn)榱思嫒菘杉由?webkit-、-o-、-ms-、-moz-、-khtml-等前綴以適應(yīng)不同的瀏覽器。
創(chuàng)建動(dòng)畫(huà)的原理是,將一套CSS樣式逐漸變化為另一套樣式。
通過(guò)@keyframes規(guī)則,您能夠創(chuàng)建動(dòng)畫(huà)。
@keyframes定義一個(gè)動(dòng)畫(huà),并定義具體的動(dòng)畫(huà)效果,比如是放大還是位移等等。
@keyframes它定義的動(dòng)畫(huà)并不直接執(zhí)行,需要借助animation來(lái)運(yùn)轉(zhuǎn)。
在動(dòng)畫(huà)過(guò)程中,您能夠多次改變這套CSS樣式。
以百分比來(lái)規(guī)定改變發(fā)生的時(shí)間,或者通過(guò)關(guān)鍵詞from和to,等價(jià)于0%和100%。
源碼
css部分
.container{
text-align:center;
perspective:500px;
-webkit-perspective:500px;
border:1pxsolid;
.example{
display:table-cell;
vertical-align:middle;
color:#fff;
width:150px;
height:150px;
background:url(../images/01.jpg)no-repeat;
@-webkit-keyframestopenter{
from{
-webkit-transform-origin:top;
-webkit-transform:rotateX(-90deg);
to{
-webkit-transform-origin:top;
-webkit-transform:rotateX(0deg);
@keyframestopenter{
from{
transform-origin:top;
transform:rotateX(-90deg);
to{
transform-origin:top;
transform:rotateX(0deg);
@-webkit-keyframestopleave{
from{
-webkit-transform-origin:top;
-webkit-transform:rotateX(0deg);
to{
-webkit-transform-origin:top;
-webkit-transform:rotateX(-90deg);
@keyframestopleave{
from{
transform-origin:top;
transform:rotateX(0deg);
to{
transform-origin:top;
transform:rotateX(-90deg);
@-webkit-keyframesbottomenter{
from{
-webkit-transform-origin:bottom;
-webkit-transform:rotateX(90deg);
to{
-webkit-transform-origin:bottom;
-webkit-transform:rotateX(0deg);
@keyframesbottomenter{
from{
transform-origin:bottom;
transform:rotateX(90deg);
to{
transform-origin:bottom;
transform:rotateX(0deg);
@-webkit-keyframesbottomleave{
from{
-webkit-transform-origin:bottom;
-webkit-transform:rotateX(0deg);
to{
-webkit-transform-origin:bottom;
-webkit-transform:rotateX(90deg);
@keyframesbottomleave{
from{
transform-origin:bottom;
transform:rotateX(0deg);
to{
transform-origin:bottom;
transform:rotateX(90deg);
@-webkit-keyframesleftenter{
from{
-webkit-transform-origin:left;
-webkit-transform:rotateY(90deg);
to{
-webkit-transform-origin:left;
-webkit-transform:rotateY(0deg);
@keyframesleftenter{
from{
transform-origin:left;
transform:rotateY(90deg);
to{
transform-origin:left;
transform:rotateY(0deg);
@-webkit-keyframesleftleave{
from{
-webkit-transform-origin:left;
-webkit-transform:rotateY(0deg);
to{
-webkit-transform-origin:left;
-webkit-transform:rotateY(90deg);
@keyframesleftleave{
from{
transform-origin:left;
transform:rotateY(0deg);
to{
transform-origin:left;
transform:rotateY(90deg);
@-webkit-keyframesrightenter{
from{
-webkit-transform-origin:right;
-webkit-transform:rotateY(-90deg);
to{
-webkit-transform-origin:right;
-webkit-transform:rotateY(0deg);
@keyframesrightenter{
from{
transform-origin:right;
transform:rotateY(-90deg);
to{
transform-origin:right;
transform:rotateY(0deg);
@-webkit-keyframesrightleave{
from{
-webkit-transform-origin:right;
-webkit-transform:rotateY(0deg);
to{
-webkit-transform-origin:right;
-webkit-transform:rotateY(-90deg);
@keyframesrightleave{
from{
transform-origin:right;
transform:rotateY(0deg);
to{
transform-origin:right;
transform:rotateY(-90deg);
}
js部分
$(function(){
//initialize
$('.container').css({
'perspective-origin':'50%0%',
'-webkit-perspective-origin':'50%0%'
$('.container.example').css({
'animation':'topleave400msforwards',
'-webkit-animation':'topleave400msforwards'
$('.container').bind('mouseentermouseleave',function(e){
vardir=getDirection($(this),e),
enter=e.type==='mouseenter',
topPerspectiveOrigin={
'perspective-origin':'50%0%',
'-webkit-perspective-origin':'50%0%'
rightPerspectiveOrigin={
'perspective-origin':'100%50%',
'-webkit-perspective-origin':'100%50%'
bottomPerspectiveOrigin={
'perspective-origin':'50%100%',
'-webkit-perspective-origin':'50%100%'
leftPerspectiveOrigin={
'perspective-origin':'0%50%',
'-webkit-perspective-origin':'0%50%'
$target=$(this).find('.example');
switch(dir){
case0:
if(enter){
$(this).css(topPerspectiveOrigin);
$target.css({
'animation':'topenter400msforwards',
'-webkit-animation':'topenter400msforwards'
}else{
$(this).css(topPerspectiveOrigin);
$target.css({
'animation':'topleave400msforwards',
'-webkit-animation':'topleave400msforwards'
break;
case1:
if(enter){
$(this).css(rightPerspectiveOrigin);
$target.css({
'animation':'rightenter400msforwards',
'-webkit-animation':'rightenter400msforwards'
}else{
$(this).css(rightPerspectiveOrigin);
$target.css({
'animation':'rightleave400msforwards',
'-webkit-animation':'rightleave400msforwards'
break;
case2:
if(enter){
$(this).css(bottomPerspectiveOrigin);
$target.css({
'animation':'bottomenter400msforwards',
'-webkit-animation':'bottomenter400msforwards'
}else{
$(this).css(bottomPerspectiveOrigin);
$target.css({
'animation':'bottomleave400msforwards',
'-webkit-animation':'bottomleave400msforwards'
break;
case3:
if(enter){
$(this).css(leftPerspectiveOrigin);
$target.css({
'animation':'
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 衣物代洗協(xié)議書(shū)
- 語(yǔ)文合作協(xié)議書(shū)
- 幼兒代餐協(xié)議書(shū)
- 裝修勞務(wù)協(xié)議書(shū)
- 小程序合同協(xié)議
- 自愿走讀協(xié)議書(shū)
- 學(xué)生招聘協(xié)議書(shū)
- 詳細(xì)雇傭合同范本
- 2026年上半年湖南株洲市市直單位公益性崗位招聘16人考試重點(diǎn)題庫(kù)及答案解析
- 資產(chǎn)頂賬協(xié)議書(shū)
- JBT 11270-2024 立體倉(cāng)庫(kù)組合式鋼結(jié)構(gòu)貨架技術(shù)規(guī)范(正式版)
- 求職OMG-大學(xué)生就業(yè)指導(dǎo)與技能開(kāi)發(fā)智慧樹(shù)知到期末考試答案章節(jié)答案2024年中國(guó)海洋大學(xué)
- JBT 7387-2014 工業(yè)過(guò)程控制系統(tǒng)用電動(dòng)控制閥
- A課堂懲罰游戲
- 整理收納師行業(yè)分析
- GB/T 228.1-2021金屬材料拉伸試驗(yàn)第1部分:室溫試驗(yàn)方法
- 氫能與燃料電池-課件-第五章-制氫技術(shù)
- 科研倫理與學(xué)術(shù)規(guī)范-課后作業(yè)答案
- 2023QC小組活動(dòng)基礎(chǔ)知識(shí)培訓(xùn)
- 生理學(xué)期末考試復(fù)習(xí)試題庫(kù)及答案
- 旅游地理學(xué) 國(guó)家公園建設(shè)與管理
評(píng)論
0/150
提交評(píng)論