css3å®ç°å¨ç»ææ
Transition å¨ç»ï¼å¨ä¸¤ä¸ªå¸§ä¹é´åæ¢
⺠transition-property: æå®å¯¹ HTML å
ç´ çåªä¸ª CSS å±æ§è¿è¡å¹³æ»æ¸åå¤çã 该å±æ§ å¯ä»¥æå® background-colorã widthã height çåç§æ åç CSS å±æ§ã all代表ææå±æ§
⺠transition-duration: æå®å±æ§å¹³æ»æ¸åçæç»æ¶é´ã
⺠transition-timing-function: æå®æ¸åçé度 ã
该é¨åæ¯æå¦ä¸å 个å¼ã
⢠ease: å¨ç»å¼å§æ¶è¾æ
¢ï¼ç¶åé度å å¿«ï¼å°è¾¾æ大é度åååæ
¢é度ã
⢠linear: 线æ§é度ãå¨ç»å¼å§æ¶çé度å°ç»ææ¶çé度ä¿æä¸åã
⢠ease-in: å¨ç»å¼å§æ¶é度è¾æ
¢ï¼ç¶åé度å å¿«ã
⢠ease-out: å¨ç»å¼å§æ¶é度å¾å¿«ï¼ç¶åé度åæ
¢ã
⢠ease-in-out: å¨ç»å¼å§æ¶é度è¾è°©ï¼ç¶åé度å å¿«ï¼å°è¾¾æ大é度åååæ
¢é度ã
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
img#targin{
position: absolute;
transition:left 2s linear;
transition:top 2s linear;
}
</style>
</head>
<body>
<img src="./jz-img1.jpg" alt="" id="targin">
<script>
var target = document.getElementById("targin");
targin.style.left="0px";
targin.style.top="0px";
document.onmousedown = function(evt){
target.style.left=evt.pageX+"px";
target.style.top=evt.pageY+"px";
}
</script>
</body>
</html>
ä¹å¯ä»¥åå¨*éï¼ææå¨ç»ææçé½éç¨å¹³æ»æ¸åï¼æ¾å¾èªå·±é¡µé¢å¾æç§ææã
*{
margin:0;
padding:0;
transitian:all 2s linear;
}
Animation å¨ç»å¯ä»¥æå®å¤ä¸ªå ³é®å¸§
⺠animation-name: æå®å¨ç»å称ã该å±æ§æå®ä¸ä¸ªå·²æçå
³é®å¸§å®ä¹ã
⺠animation-duration: æå®å¨ç»çæç»æ¶é´ã
⺠animation-timing-function: æå®å¨ç»çååé度ã
⺠animation-delay: æå®å¨ç»å»¶è¿å¤é¿æ¶é´æå¼å§æ§è¡ã
⺠animation-iteration-count: æå®å¨ç»ç循ç¯æ§è¡æ¬¡æ° ã
animation: è¿æ¯ä¸ä¸ªå¤åå±æ§ã该å±æ§çæ ¼å¼ä¸ºï¼ animation-name animation-duration animation-timing-function animation-delay animation-iteration-count, 使ç¨è¯¥å±æ§å¯ä»¥åæ¶æå® animation-nameã animation-duration ã animation-timing-functionã animation-delay å animation-iteration-count çå±æ§ã
**ï¼ï¼æå®å¨ç»ç循ç¯æ é次ï¼ï¼
animation-iteration-count: infinite;**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
@keyframes li{
0%{
left: 200px;
top:0px;
/* æ转å ç¼©æ¾ */
transform: rotate(0deg) scale(1);
}
40%{
left: 450px;
transform: rotate(40deg) scale(0.4);
}
60%{
left: 990px;
transform: rotate(180deg) scale(0.9);
}
100%{
left: 200px;
transform: rotate(0deg) scale(1);
}
}
img#targin{
position: absolute;
left: 200px;
}
.anime{
animation-name: li;
/* æ´ä¸ªå¨ç»æ§è¡æ¶é´ */
animation-duration:3s;
/* æ éæ¬¡å¾ªç¯ */
animation-iteration-count:infinite;
}
</style>
</head>
<body>
<img src="./jz-img1.jpg" alt="" id="targin">
<button οnclick="document.getElementById('targin').className='anime';">å¼å§å¨ç»</button>
<button οnclick="document.getElementById('targin').className='';">å
³éå¨ç»</button>
</body>
</html>
è·å¾htmlä¸id为idååçå
ç´ ï¼ç»ä»å ä¸class=âanimeâçæ ·å¼ï¼
document.getElementById(âidååâ).className=âanimeâ;
è·å¾htmlä¸id为idååçå
ç´ ï¼ç»ä»å ä¸class=ââçæ ·å¼ï¼ä¹å°±æ¯ç©ºæ ·å¼ï¼
document.getElementById(âidååâ).className="";
<button οnclick="document.getElementById('targin').className='anime';">å¼å§å¨ç»</button>
<button οnclick="document.getElementById('targin').className='';">å
³éå¨ç»</button>
å¾çèªå·±æ¾ä¸å¼ æ¿ä»£ï¼æ好æ¯å¨å¾.gifæ ¼å¼ï¼èªå·±å¤å¨æï¼å¯ä»¥å®ç°å¾å¤ç®åå¨ç»ã