




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第基于JS實現(xiàn)動態(tài)跟隨特效的示例代碼目錄演示技術(shù)棧源碼css部分js部分
演示
技術(shù)棧
這次用到了關(guān)于css的一些功能,和jQuery。
CSS3中添加的新屬性animation是用來為元素實現(xiàn)動畫效果的,但是animation無法單獨擔當起實現(xiàn)動畫的效果。承載動畫的另一個屬性@keyframes。使用的時候為了兼容可加上-webkit-、-o-、-ms-、-moz-、-khtml-等前綴以適應不同的瀏覽器。
創(chuàng)建動畫的原理是,將一套CSS樣式逐漸變化為另一套樣式。
通過@keyframes規(guī)則,您能夠創(chuàng)建動畫。
@keyframes定義一個動畫,并定義具體的動畫效果,比如是放大還是位移等等。
@keyframes它定義的動畫并不直接執(zhí)行,需要借助animation來運轉(zhuǎn)。
在動畫過程中,您能夠多次改變這套CSS樣式。
以百分比來規(guī)定改變發(fā)生的時間,或者通過關(guān)鍵詞from和to,等價于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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 臨聘合同終止協(xié)議書模板
- 訂單合同如何簽署協(xié)議書
- 黃金積存合同協(xié)議書范本
- 刮瓷工程合同協(xié)議書
- 素食店創(chuàng)業(yè)計劃書syb
- 花束銷售計劃書
- 清潔能源創(chuàng)業(yè)計劃書可持續(xù)發(fā)展的新能源解決方案
- 醫(yī)療項目可行性研究報告
- 統(tǒng)編版-2025秋四年級語文上冊-【16 麻雀】交互課件
- 健身房前期方案
- 觸電事故桌面推演方案
- 護理風險評估及填寫要求
- 《中興通訊績效管理制度》-人事制度表格【管理資料】
- 微邦生物技術(shù)生活污水處理中的應用
- 鐵路工務技術(shù)手冊
- (完整版)硬件測試規(guī)范
- 2006年工資標準及套改對應表
- DBJ∕T 13-183-2014 基樁豎向承載力自平衡法靜載試驗技術(shù)規(guī)程
- 張雙樓煤礦安全評價報告(出版稿10.14)
- [模板]健康教育處方
- 婦產(chǎn)科英語詞匯
評論
0/150
提交評論