Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Avinash Pandit
6,623 PointsCSS transition not working in chrome
Hi! I'm a bit new so please bear with me if this is out of context or a bit long.
I was trying to create a simple game, the first part of which was to animate the ball movement inside of a box depending on where it hits.
I am not able to work with the transitions in CSS (I have checked in Chrome and Safari). I have put in the relevant prefixes for browser supper and I am checking for "transitioned" state in event listener. From the console logs, I don't find it happening.
My html code is below:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Simple game</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div id="canvas">
<div id="ball"></div>
</div>
<button type="button">Start animation</button>
<script type="text/javascript" src="javascript.js"></script>
</body>
</html>
Relevant CSS snippet:
#ball{
width: 30px;
height: 30px;
display: inline-block;
border-radius: 100%;
background-color: blue;
position:absolute;
-webkit-transition: left 1s ease-in-out, top 1s ease-in-out;
-moz-transition: left 1s ease-in-out, top 1s ease-in-out;
-o-transition: left 1s ease-in-out, top 1s ease-in-out;
transition: left 1s ease-in-out, top 1s ease-in-out;
top:300px;
left: 0px;
}
Relevant javascript snippets :
var ball = document.querySelector("#ball");
var button = document.querySelector("button[type=button]");
//add mouse click event listener to button. Call initialize when clicked
button.addEventListener("click",initialize,false);
//add transitionend event listener to ball. Call pathdecider
ball.addEventListener("transitionend",pathdecider,false);
Thanks!