components
This commit is contained in:
parent
304d578b54
commit
6fb4aabcba
344 changed files with 669 additions and 406 deletions
43
7-animation/2-css-animations/boat.view/index.html
Normal file
43
7-animation/2-css-animations/boat.view/index.html
Normal file
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<img src="https://js.cx/clipart/boat.png" id="boat">
|
||||
|
||||
<script>
|
||||
boat.onclick = function() {
|
||||
|
||||
this.onclick = null; // only the first click should start the animation
|
||||
|
||||
let times = 1;
|
||||
|
||||
function go() {
|
||||
if (times % 2) {
|
||||
boat.classList.remove('back');
|
||||
boat.style.marginLeft = 100 * times + 200 + 'px';
|
||||
} else {
|
||||
boat.classList.add('back');
|
||||
boat.style.marginLeft = 100 * times - 200 + 'px';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
go();
|
||||
|
||||
boat.addEventListener('transitionend', function() {
|
||||
times++;
|
||||
go();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
11
7-animation/2-css-animations/boat.view/style.css
Normal file
11
7-animation/2-css-animations/boat.view/style.css
Normal file
|
@ -0,0 +1,11 @@
|
|||
#boat {
|
||||
margin-left: 0;
|
||||
cursor: pointer;
|
||||
transition: margin-left 3s ease-in-out;
|
||||
}
|
||||
|
||||
/* flipping the picture with CSS */
|
||||
.back {
|
||||
transform: scaleX(-1);
|
||||
filter: fliph;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue