Trigger CSS animation with checkbox inside a fieldset - html

I try to trigger an animation only when a checkbox is checked.
I have the following code :
<div data-role="fieldcontain" >
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="checkbox" class="mediaCheckbox" id="playCheck"/>
<label data-role="button" class="fa fa-play" id="play" for="playCheck"></label>
<input type="checkbox" class="mediaCheckbox" id="muteCheck"/>
<label data-role="button" class="fa fa-bell" id="mute" for="muteCheck"></label>
</fieldset>
</div>
<div id="stuffToAnimate"></div>
and the following CSS :
#stuffToAnimate {
position: relative;
-webkit-animation: ball 11s ease-in-out 0s infinite normal; /* Chrome, Safari, Opera */
-webkit-animation-play-state: paused;
}
#playCheck:checked **XXX**{
-webkit-animation-play-state: running;
}
#-webkit-keyframes ball {
0% {top:5%;}
40% {-webkit-transform: rotate(0deg);}
50% {-webkit-transform: rotate(180deg);top:80%;}
90% {-webkit-transform: rotate(180deg);}
100% {-webkit-transform: rotate(360deg);top:5%;}
}
My problem is: How to complete the **XXX** selector in order to trigger the animation. I could put the checkbox #playCheck in the same level as #stuffToAnimate, but it would mess up my presentation.

you could use jquery to give #stuffToAnimate a class
$('#playCheck:checkbox').click(function() {
if ($(this).is(":checked"))
{
$("#stuffToAnimate").addClass("animate");
}
else {
$("#stuffToAnimate").removeClass("animate");
}
});
your css will look like this
.animate{
-webkit-animation-play-state: running;
}

Related

In closing Angular dialog create a transition

I have created an animation when the dialog is opening but I want the same when the Angular dialog is closing.
This is my code for opening dialog with animation:
<div class="container">
<div class="body-container" [ngClass]="getBorderColor()">
</div>
<button mat-dialog-close>Cancel</button>
</div>
.body-container {
animation: animation-name .5s ease-out forwards;
}
#keyframes animation-name {
0% {
transform: translateX(100%); }
100% {
transform: translateX(0%);
}
}
And here is the stackblitz I have created.
https://stackblitz.com/edit/slow-dialog-f5nnnr?file=app%2Fdialog-overview-example-dialog.css

CSS Animations skip in Firefox when animated element is out of viewport

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>

Can't apply :not() to include div containers

I am trying to fade in everything on the screen except an image. I want the image to transform: scales(); bigger and than back down to original size.I have two container boxes that have some text and a form that I want to all fade in after the image.
I can get the image to animate and then everything else fade in but the div containers themselves do not animate. So there will be two empty boxes on the screen, the image animates and then the contents of the div fade in.
Here is my code:
.fadeIn :not(#ipad) {
-webkit-animation: fadeIn 3s ease;
-moz-animation: fadeIn 3s ease;
-ms-animation: fadeIn 3s ease;
-o-animation: fadeIn 3s ease;
animation: fadeIn 3s ease;
}
<div class="title fadeIn" id="title"><b>Curriculum and Instruction iPad Setup</b></div>
<div class="info-container fadeIn" id="info-container">
<img src="img/IPad_3.png" id="ipad">
<form action="login_complete.php" method="post" id="loginForm">
<div class="campus-container">
<input type="radio" name="campus" value="STE" /><span><b>Stephenville</b></span>
<input type="radio" name="campus" value="FTW" /><span><b>Fort Worth</b></span>
</div>
<input type="submit" value="Submit" onclick="loadingSpinner();" />
</form>
</div>
When I take off :not(#ipad) everything, including the image, fades in together. I want the image to not get the fade in animation.
I looked here but that didn't seem to work. I also found this but also no go.
EDITED:
Sorry about not enough css code:
the fade in
#keyframes fadeIn {
0% { opacity: 0; }
50% { opacity: 0; }
100% { opacity: 1; }
}
image animation
#keyframes zoomOut {
0% {
opacity: 0;
}
5% {
opacity: 1;
}
50% {
-webkit-transform: scale(5);
-moz-transform: scale(5);
-ms-transform: scale(5);
-o-transform: scale(5);
transform: scale(5);
}
100% { }
}
if you nest <img src="img/IPad_3.png" id="ipad">
inside <div class="info-container fadeIn" id="info-container">
you should not expect it to work.
that's all it takes. you have to rethink your document structure.
besides, css does not allow you to write look ahead expressions so you don't have any other choice but to change the document structure.
one way to fix it would be this:
change the info-container div to this:
<div class="info-container fadeIn iPad" id="info-container">
and change css from .fadeIn :not(#ipad) to .fadeIn:not(.iPad)
or alternatively just remove fadeIn from that div.
you could also change your css selector to this: .fadeIn {
and change your html to this:
<div class="title fadeIn" id="title"><b>Curriculum and Instruction iPad Setup</b></div>
<div class="info-container" id="info-container">
<img src="img/IPad_3.png" id="ipad">
<form action="login_complete.php" class="fadeIn" method="post" id="loginForm">
<div class="campus-container">
<input type="radio" name="campus" value="STE" /><span><b>Stephenville</b></span>
<input type="radio" name="campus" value="FTW" /><span><b>Fort Worth</b></span>
</div>
<input type="submit" value="Submit" onclick="loadingSpinner();" />
</form>
</div>

Adding class via js won't trigger css animation

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.

how to change size of the element using css?

I am trying to do transform a image using css keyframe
I have something like
#-webkit-keyframes blinkscale {
0% {
transform: scale(1,1)
}
50% {
transform: scale(0.1,0.1)
}
100% {
transform: scale(3,3)
}
}
.addScale {
-webkit-animation: blinkscale 2s;
-webkit-animation-iteration-count: infinite;
-moz-animation: blinkscale 2s;
-moz-animation-iteration-count: infinite;
-o-animation: blinkscale 2s;
-o-animation-iteration-count: infinite;
}
html
<img src='test.jpg' class='addScale' />
It works if I change my keyframe to
#-webkit-keyframes blinkscale {
0% {background: yellow;}
50% {background: green;}
100% {background: blue;}
}
but not the scale one. Can anyone help me about it? Thanks a lot!
This should do it for you. Just have to make sure the vendor prefixes persist.
CSS:
#-webkit-keyframes blinkscale {
0% {
-webkit-transform: scale(1,1)
}
50% {
-webkit-transform: scale(0.1,0.1)
}
100% {
-webkit-transform: scale(3,3)
}
}
Also to note, you have -moz- and -o- animation set to .addScale so be sure to set keyframes to accommodate all those vendor prefixes and don't forget the standard animation as well.
This link here should be of use Keyframe Animations
Maybe you haven't included the proper browser help, in the webkit keyframes blinkscale, I only see the help for mozilla,.