Animation Not Running on Site Load
See original GitHub issueIssue
The animation doesn’t work on my Personal Site when it works on CodePen. I have tried using webpack and such, but have not gotten the almost identical code, to work. The only things I really changed are formatting, as well. Here listed below, is my HTML, JS, and CSS.
Code
HTML
<!DOCTYPE html>
<html>
<head>
<title>Movement Animation</title>
<meta content="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="theme.css" />
</head>
<body>
<script src="index.js"></script>
<div class="container">
<div class="bar bar1"></div>
<div class="ball"></div>
<div class="bar bar2"></div>
</div>
</body>
</html>
JS
import anime from 'animejs';
import $ from "jquery";
var loop = true;
var easing = 'linear';
var direction = 'alternate';
anime({
targets: '.ball',
translateX: 470,
translateY: 100,
easing,
loop,
direction,
background: [
{ value: '#573796' },
{ value: '#FB89FB' },
{ value: '#FBF38C' },
{ value: '#18FF92' },
{ value: '#5A87FF' }
]
})
var ballTimeline = anime.timeline({
loop,
direction
})
var bar2Timeline = anime.timeline({
loop,
direction
})
var bar1Timeline = anime.timeline({
loop,
direction
})
ballTimeline
.add({
targets: '.ball',
translateY: 100,
translateX: 470,
easing
}).add({
targets: '.ball',
translateY: 0,
translateX: 0,
easing
}).add({
targets: '.ball',
translateY: '-80',
translateX: 470,
easing
})
bar2Timeline
.add({
targets: '.bar2',
translateY: 100,
easing,
background: '#573796'
}).add({
targets: '.bar2',
translateY: 0,
easing,
background: '#FB89FB'
}).add({
targets: '.bar2',
translateY: '-100',
easing,
background: '#FBF38C'
})
bar1Timeline
.add({
targets: '.bar1',
translateY: '-80',
easing,
background: '#18FF92'
}).add({
targets: '.bar1',
translateY: 10,
easing,
background: '#5A87FF'
}).add({
targets: '.bar1',
translateY: 60,
easing,
background: '#FF1461'
})
CSS
body {
background: #000000;
text-align: center;
}
.container {
width: 500px;
display: inline-block;
transform: translateY(200px);
}
.bar {
background: #FFFFFF;
width: 10px;
height: 100px;
}
.bar1 {
float: left;
}
.bar2 {
float: right;
}
.ball {
background: #FFFFFF;
width: 10px;
height: 10px;
position: relative;
top: 45px;
left: 10px;
}
Thank you for your kind help!
P.S. The code here, has been updated!
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
Top Results From Across the Web
CSS Animations Not Working? Try These Fixes - HubSpot Blog
Learn how to fix common CSS animation error and get your animations looking how you want them.
Read more >How to prevent a CSS keyframe animation from running on ...
Another way around this is to initially hide the element, make sure the animation plays while it is hidden, then make it visible....
Read more >Animations not working on page load - WordPress.org
I'm seeing an issue where an animated block element “flashes” the entire block on page load (shows it all) and then starts the...
Read more >How to Create Animation on Page Load - W3docs
In this snippet, you will find information and examples on creating an animation on page load. For that, use CSS @keyframes and some...
Read more >CSS Animations tips and tricks - MDN Web Docs
This article is a collection of tips and tricks we've found that may make your work easier, including how to run a stopped...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No problem! I’m glad it worked!
Yeah, I have tried it using an ES6 module, a require statement, and as a script tag reference. I am using jquery as well, but even without it, wit the examples on its repo, it still doesn’t seem to be working on any of my browsers I have, and I have 4 of them.
EDIT: I got it to work!