Skip to content

Commit

Permalink
Create floating_boat.js
Browse files Browse the repository at this point in the history
  • Loading branch information
octoiron committed Oct 9, 2021
1 parent f572aeb commit 426ce53
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Iron Octo/floating_boat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<style>
#boat {
margin-left: 0;
cursor: pointer;
transition: margin-left 3s ease-in-out;
}

/* flipping the picture with CSS */
.back {
transform: scaleX(-1);
filter: fliph;
}

</style>
<title>Floating Boat</title>
</head>

<body>

<img src="boat.png" id="boat">

<script>
boat.onclick = function() {

this.onclick = null;

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>

0 comments on commit 426ce53

Please sign in to comment.