I have a modified version of animate.css (added some delay, new timings and new positions), and it works really great when the classes are set by default (html document). But when I am adding the animate class dynamically via js, the animation is not executed!
Even more annoying, I did have it working at some point, but I can't get it to work again (using gumby framework and inview js to add a class when the element is on screen (adding .animated)) . The left box had the classes already in the html, and the right box have the .animate class added by js.
Example:
http://onepageframework.com/28_2_14/strange_anim.html
Any ideas why the right box is not animating?
Using the Gumby inview extension: http://gumbyframework.com/docs/extensions/#!/inview
Edit: added html:
<div class="six columns text-center fadeInLeftMedium delay_2 animated">
<!-- left box content here -->
</div>
<div class="six columns text-center fadeInLeftMedium delay_2 inview" data-classname="animated">
<!-- right box content here -->
</div>
css:
.animated {
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
}
.delay_2 {
-webkit-animation-delay: 2s;
-moz-animation-delay: 2s;
-o-animation-delay: 2s;
animation-delay: 2s;
}
#-webkit-keyframes fadeInLeftMedium {
0% {
opacity: 0;
-webkit-transform: translateX(-400px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}
#-moz-keyframes fadeInLeftMedium {
0% {
opacity: 0;
-moz-transform: translateX(-400px);
}
100% {
opacity: 1;
-moz-transform: translateX(0);
}
}
#-o-keyframes fadeInLeftMedium {
0% {
opacity: 0;
-o-transform: translateX(-400px);
}
100% {
opacity: 1;
-o-transform: translateX(0);
}
}
#keyframes fadeInLeftMedium {
0% {
opacity: 0;
transform: translateX(-400px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
.fadeInLeftMedium {
-webkit-animation-name: fadeInLeftMedium;
-moz-animation-name: fadeInLeftMedium;
-o-animation-name: fadeInLeftMedium;
animation-name: fadeInLeftMedium;
}
The reason is the same why you can't re-trigger CSS based animations by just subsequently removing and adding a class. The reason is that browsers batch-up these modifications and optimize away the animation.
Reason and solutions are discussed here.
From the article, your options are (paraphrased):
Add a small delay before re-adding the class (not recommended)
Clone the element, remove it, and insert the clone
Have 2 identical animations (attached to different css rules) and switch between them
Trigger a reflow between removing and adding the class name:
element.classList.remove("run-animation");
// element.offsetWidth = element.offsetWidth; //doesn't work in strict mode
void element.offsetWidth; // reading the property requires a recalc
element.classList.add("run-animation");
Change (cycle) the element's CSS animation-play-state attribute to paused or running (does not restart animation)
By swaping the classes, it looks like it got it to work (aminated in the class, and fadeInLeftMedium as the data-classname):
<div class="six columns text-center fadeInLeftMedium delay_2 animated">
<!-- left box content here -->
</div>
<div class="six columns text-center animated delay_2 inview" data-classname="fadeInLeftMedium">
<!-- right box content here -->
</div>
I think you just need to add animated as a class rather than as data-classname="animated"...
So basically:
<div class="six columns text-center fadeInLeftMedium delay_2 inview" data-classname="animated">
<!-- right box content here -->
</div>
Should be:
<div class="six columns text-center fadeInLeftMedium delay_2 inview animated">
<!-- right box content here -->
</div>
Otherwise the animation lacks a specified animation duration and without the animation-duration property specified the animation won't work.
Related
I'm making a website using online Wix templates but the specific template didn't have all the things I needed so then I had to learn a little HTML/CSS. (I'm pretty new to it)
I've written the code below which shows a list of text (Company names) by sliding upwards. Once the user hovers the mouse on the text, the slider stops (onmouseover) and when the user moves the mouse pointer away from it the slider goes back to the same motion (onmouseout).
Link to some code: https://www.codepile.net/pile/WAJX9nrE
Okay so my questions are:
How can I animate this code so that when the webpage first loads this box will load in with some sort of animation?
And also instead of Company names, how can I add hyperlinks to the dedicated company's website?
To do this, add an animation for the element on page load through CSS. In the following example, this animation is called move-up which will run for 1 second. Additionally, to make a marquee, add an additional animation that loops. This is called slide in the following snippet which repeats every 16 seconds. The HTML of the companies will need to be duplicated to provide seamless looping. Finally, use a transition and the CSS :hover property to pause the animations when the mouse is over the card container. Here is a demo.
body {
overflow-y: hidden;
}
.card {
width: 200px;
height: 100px;
border-radius: 5px;
box-shadow: 0 5px 10px #888888;
padding: 10px;
margin: 20px;
display: inline-block;
/* Adds animation that runs on load */
animation-name: move-up;
animation-duration: 1s;
/* Adds transition */
transition: 0.3s;
/* Safari versions 8 and older */
-webkit-animation-name: move-up;
-webkit-animation-duration: 0.3s;
-webkit-transition: 0.5s;
}
/* Styles the container the card is in */
.card-container {
width: 100%;
overflow-y: show;
white-space: nowrap;
animation-name: slide;
animation-duration: 16s;
animation-iteration-count: infinite;
animation-timing-function: linear;
/* More Safari compatibility... */
-webkit-animation-name: slide;
-webkit-animation-duration: 16s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
}
/* Plays transition on hover */
.card:hover {
transform: scale(1.1);
}
.card-container:hover {
animation-play-state: paused;
}
/* Defines animation on load */
#keyframes move-up {
from {
opacity: 0;
transform: translateY(50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Sliding animation */
#keyframes slide {
from {
transform: translateX(0);
}
to {
transform: translateX(-1320px);
}
}
/* Safari versions 8 and older */
#-webkit-keyframes move-up {
from {
opacity: 0;
transform: translateY(50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
#-webkit-#keyframes slide {
from {
transform: translateX(0);
}
to {
transform: translateX(-1320px);
}
}
<body>
<div class="card-container">
<div class="card">Company 1</div>
<div class="card">Company 2</div>
<div class="card">Company 3</div>
<div class="card">Company 4</div>
<div class="card">Company 5</div>
<!-- Duplicate cards are neccecary so that there is seemless looping. You may need even more if the cards do not fill the entire width of the page. -->
<div class="card">Company 1</div>
<div class="card">Company 2</div>
<div class="card">Company 3</div>
<div class="card">Company 4</div>
<div class="card">Company 5</div>
</div>
</body>
The link you provided is not working please repair the link.
Try using this JSFiddle in Chrome and in Firefox.
Here's the code:
(HTML)
<div class="slide-down">
<h1>Hello!</h1>
</div>
(CSS)
.slide-down {
font-size: 3em;
-moz-animation-duration: 3s;
-webkit-animation-duration: 3s;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-moz-animation-name: slideDown;
-webkit-animation-name: slideDown;
}
#-moz-keyframes slideDown {
0% {
-moz-transform:translateY(-300px);
}
100% {
-moz-transform:translateY(0px);
}
}
#-webkit-keyframes slideDown {
0% {
-webkit-transform: translateY(-300px);
}
100% {
-webkit-transform: translateY(0px);
}
}
My issue is that it works in Chrome but only works in Firefox when the starting coordinates (at the "0%" point of the animation) of the animated div are within the viewport. Otherwise, it can completely skip the animation. Try changing the translateY() parameter to something more conservative, like -50px, and it will work.
Is there a workaround for this? It would be nice to be able to bring something in from outside the screen without having to write a script to figure out what its initial y-coordinate should be.
I would consider animating the margin instead:
.slide-down {
font-size: 3em;
animation:slideDown 3s forwards;
}
#keyframes slideDown {
0% {
margin-top:-300px;
}
100% {
margin-top:0;
}
}
<div class="slide-down">
<h1>Hello!</h1>
</div>
I am trying to animate a button making it translate a little bit to the right for a specific time, but somehow the transition never happens.
#keyframes moveXpath {
0% {
transform: translateX(-10px);
}
100% {
transform: translateX(100px);
}
}
.btn-animate {
animation-name: moveXpath;
animation-duration: 10s;
}
<body>
<div class="container">
<h1>button animation</h1>
<div class="buttons">
rotating button
</div>
</div>
</body>
lost some time and can't figure out what is wrong any help?
Anchor are inline elements transform does not work on these type of elements.
Add a different display (block or inline-block) to your anchor
.btn-animate {
animation-name: moveXpath;
animation-duration: 10s;
display: inline-block;
}
Source: w3.org
I'm new to angular, and I have a CSS stylesheet with animations i want to apply to a view when it is called. I tried searching online but I don't understand the information.
My CSS:
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
#-webkit-keyframes fadeInLeft {
from {
opacity: 0;
-webkit-transform: translate3d(-2000px, 0, 0);
transform: translate3d(-2000px, 0, 0);
}
to {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
#keyframes fadeInLeft {
from {
opacity: 0;
-webkit-transform: translate3d(-2000px, 0, 0);
transform: translate3d(-2000px, 0, 0);
}
to {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
.fadeInLeft{
-webkit-animation-name: fadeInLeft;
animation-name: fadeInLeft;
}
My first view(the one that's loaded first):
<body id="login">
<div>
<div id="container" class="container-fluid">
#RenderBody()
</div>
</div>
</body>
My partial view:
<div class="animated fadeInLeft">
<h1 class="large">Welcome.</h1>
</div>
When the page is loaded where there is renderbody() my partial view will be.
I want to to put a fadeInLeft animation on it when it is called by the first view.
I hope my question is clear enough, I'm really very new to Angular, and used to working with CSS animations on regular Html.
I would recommend using ngAnimate module.
Then write your CSS like-
.animated .ng-enter {animation: fadeInLeft 1s both ease-in;}
I have a div I've animated on hover. However when I am not hovering the div won't disappear
This is what the entire thing looks like in action: http://jsfiddle.net/Vbxtc/
This is the html:
<nav>
<div id="controls">
<button id="playButton">Play</button>
<div id="defaultBar">
<div id="progressBar"></div>
</div>
<button id="vol" onclick="level()">Vol</button>
<button id="mute">Mute</button>
<button id="full" onclick="toggleFullScreen()">Full</button>
</div>
<div id="playlist" class="animated fadeInRight">
<div>cats</div>
<div>cats</div>
<div>cats</div>
</div>
</nav>
This is the CSS i've made:
#playlist{
position:absolute;
display:block;
border:1px solid red;
height: 82%;
width: 25%;
top: 20px;
right: 0px;
z-index: 2;
float:right;
padding: 0px;
margin: 0px;
color:white;
background-color:#999999;
opacity: 0;
}
#playlist:hover {
opacity: 1;
}
This is the animation im trying
.animated:hover {
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-ms-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
}
.fadeInRight {
-webkit-animation-name: fadeInRight;
-moz-animation-name: fadeInRight;
-o-animation-name: fadeInRight;
animation-name: fadeInRight;
}
#-webkit-keyframes fadeOutRight {
0% {
opacity: 1;
-webkit-transform: translateX(0);
}
100% {
opacity: 0;
-webkit-transform: translateX(20px);
}
}
#-webkit-keyframes fadeInRight {
0% {
opacity: 0;
-webkit-transform: translateX(20px);
}
100% {
opacity: 1;
-webkit-transform: translateX(0);
}
}
I noticed that when you time the mouse over exactly right (hover for about 1 second and move mouse up top), it DOES fade out nicely.
The other thing is, if you add the class fadeOutRight as follows:
<div id="playlist" class="animated fadeInRight fadeOutRight">
It fades out too quickly.
I know I didn't help much but the answer lies in the timing.
Also, if you had the fadeOutRight class on, for example, the sidebar, it works nicely!
<aside id="sidebar" class="fadeOutRight">
Perhaps, put the class of fadeOutRight on everything EXCEPT the fadeInRight div.
It's not a good idea to play with an element position in the hover state.
Even if you get to program it right (that is not easy), most of the time the user won't understand what's happening.
You can get flickering scenarios where, without the user moving the cursor, your div leaves the cursor position, canceling the hover, the div re-entering the cursor, the hover triggering , and so on.
I would recomend to trigger the hover on another div that covers the full area where the moving div will be.