I have a component that needs to slide in from left with an animation. But I need the same component to disappear instantly. But with the following code, the component comes in with the animation I want, but takes 2 seconds to disappear. How should I change this, so the component would disappear instantly?
#keyframes slide-in {
from {left: -350px;}
to {left: 0;}
}
.how {
position: relative;
animation-name: slide-in;
animation-duration: 2s;
}
for the component to disappear, I am using an ng-if (AngularJS).
<div class="m-b col-md-6 how">
<p ng-if="active==1;" class="how"> First </p>
<p ng-if="active==2;" class="how"> Second </p>
<p ng-if="active==3;" class="how"> Third </p>
<p ng-if="active==4;" class="how"> Forth</p>
</div>
And here is the code that actually modifies the value of active:
<div class="m-b col-md-6">
<div class="m-b">
<butto ng-click="active=1;"> Step 1</button>
</div>
<div class="m-b">
<button ng-click="active=2;">Step 2</button>
</div>
<div class="m-b">
<button ng-click="active=3;">Step 3</button>
</div>
<div class="m-b">
<button ng-click="active=4;">Step 4</button>
</div>
</div>
So the component does disappear with the code above, but it takes 2 seconds for it to disappear!
To make an element visually disappear, you can set the opacity to 0. The element will still occupy space on the page.
JSFiddle
#keyframes slide-in {
0% {left: -350px; opacity: 1;}
99% {left: 0; opacity: 1;}
100% {left: 0; opacity: 0;}
}
.how {
opacity: 0;
position: relative;
animation-name: slide-in;
animation-duration: 2s;
}
Related
I'm looking into CSS transforms and I cant get this one part to work.
#photo-container img {
transition: transform 2s, transform-origin 2s;
}
#container-1 img:hover {
transform: rotate(45deg);
transform-origin: 0 0;
}
#container-2 img:hover {
transform: rotate(1.5turn);
transform-origin: 50%, 50%;
}
#container-3 img:hover {
transform: scale(1.5);
transform-origin: 0 0;
}
<div class="photo-container" id="container-1">
<div class="photo">
<img src="http://placehold.it/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
The three classes HTML elements are the same as the one posted below.
My question is that say I change the transform origin to 0 0, and it has a transform set to rotate, when the rotate occurs and finishes, instead of returning to its original position the same way it did to get there, it recenters itself, then goes to that point that was specified in the rotate function and does it from there.
Is there something I missed here or is this the normal functionality?
Edit. i stuffed something up. sorry to bother
Try to add transform-origin to images without hover. And change #photo-container to .photo-container I can't see another problem with it.
.photo-container {
display: inline-block;
}
.photo-container img {
transition: transform 2s, transform-origin 2s;
transform-origin: 0 0;
}
#container-1 img:hover {
transform: rotate(45deg);
}
#container-2 img:hover {
transform: rotate(1.5turn);
}
#container-3 img:hover {
transform: scale(1.5);
}
<div class="photo-container" id="container-1">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
<div class="photo-container" id="container-2">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
<div class="photo-container" id="container-3">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
I have the following CSS:
.element{
position:relative;
transition:all 1s;
-webkit-transform: rotateX(1deg) rotateZ(1deg) rotateY(0deg);
-webkit-transform-style: preserve-3d;
}
.spun{
.element{
top:260px;
-webkit-transform: rotateX(45deg) rotateZ(45deg) rotateY(0deg);
}
}
and HTML
<div class="element" id="element-1">
<div class="graphic-wrap">
Text 1
</div>
</div>
<div class="element" id="element-2">
<div class="graphic-wrap">
Text 2
</div>
</div>
<div class="element" id="element-3">
<div class="graphic-wrap">
Text 3
</div>
</div>
When I add a class of spun to the body, everything jumps before moving into position. You can see it actually goes off the screen, even though if you compare the position of where it starts, and where it ends, they are really similar:
Demo: http://codepen.io/EightArmsHQ/pen/dadff4f8e9f63e9f825693865d1c9354
If, however I don't add the spun class, and instead gradually increment the values in developer tools, it gradually moves how I want it to.
How can I prevent everything from jumping?
This is because the .element doest have an initial top position so there is no state for it to transform from.
Simply give the .element a starting position. Eg:
$('body').click(function(){
$(this).toggleClass('spun');
})
.element {
top: 0px;
position: relative;
transition: all 1s;
transform: rotateX(1deg) rotateZ(1deg) rotateY(0deg);
transform-style: preserve-3d;
transform-origin: 50% 50%;
}
.spun .element {
top: 260px;
transform: rotateX(45deg) rotateZ(45deg) rotateY(0deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="element" id="element-1">
<div class="graphic-wrap">
Text 1
</div>
</div>
<div class="element" id="element-2">
<div class="graphic-wrap">
Text 2
</div>
</div>
<div class="element" id="element-3">
<div class="graphic-wrap">
Text 3
</div>
</div>
I have 2 images which I'm trying to make as my background image. I want those images to fade in and fade out after 2 seconds. At present the change in the background image is happening when I hover over the image. How can I make this change happen automatically, without any hover?
.bground {
width:100%;
position:relative;
background: url(../img/bg1.jpg) no-repeat top center;
-webkit-transition-property: background;
-webkit-transition-duration: 1s;
}
.bground:hover {
background: url(../img/bg2.jpg) no-repeat top center;
}
<section id="bground" class="bground">
<div class="display">
<img src="img/logo.png" alt="Logo">
</div>
<div class="page-scroll">
<a href="#about" class="btn btn-circle" style="color:#000000">
<i class="fa fa-angle-double-down animated"></i>
</a>
</div>
</section>
You can use animation property
I've do this code for you (with some img):
.bground {
width: 200px;
height: 200px;
position:relative;
background: url("http://www.bizreport.com/2011/02/03/android-logo-200x200.jpg") no-repeat top center;
-webkit-animation: 4s linear 0s infinite alternate test;
-o-animation:4s linear 0s infinite alternate test;
animation:4s linear 0s infinite alternate test;
}
#keyframes test {
0% {background-image: url("http://tech21info.com/admin/wp-content/uploads/2013/03/chrome-logo-200x200.png");}
100% {background-image: url(http://www.bizreport.com/2011/02/03/android-logo-200x200.jpg");}
}
<section id="bground" class="bground">
<div class="display">
</div>
<div class="page-scroll">
<a href="#about" class="btn btn-circle" style="color:#000000">
<i class="fa fa-angle-double-down animated"></i>
</a>
</div>
</section>
Hi I have to show a grid of images; every item in the grid is a different product and it has 2-3 images but only the first image should be visible. On mouse hover should loop the other images. How can I do this in wordpress?
I thought to insert a gallery for every product and from css display only the first child and display:none all the other images. But now I don't know how to add slide on mouse over.
Any other solution?
thank you
According to the provided snippet, this is the CSS that should do the job.
In your sample, I just added a wrapper div, that will be our viewport (meaning the container that will just display one image at a time).
I also removed all the br that clear the float, as the CSS uses the float to display all images side by side for the slide.
<div id="viewport">
<div id="gallery-1" class="gallery galleryid-20 gallery-columns-1 gallery-size-collection">
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<a data-lightbox-gallery="lightbox-gallery-1" href="image1.jpg" data-rel="lightbox-gallery-1">
<img id="image1" style="border: medium none;" class="attachment-collection" alt="image1" height="420" width="300">
</a>
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<a data-lightbox-gallery="lightbox-gallery-1" href="image2.jpg" data-rel="lightbox-gallery-1">
<img id="image2" style="border: medium none;" class="attachment-collection" alt="image2" height="420" width="300">
</a>
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<a data-lightbox-gallery="lightbox-gallery-1" href="image3.jpg" data-rel="lightbox-gallery-1">
<img id="image3" style="border: medium none;" class="attachment-collection" alt="image3" height="420" width="300">
</a>
</dt>
</dl>
</div>
</div>
Note that I added some ids for all images just to have different colors through the CSS
Now, related to the CSS part:
/* THIS IS JUST FOR STYLING FAKE IMAGES, NOT PART OF THE SOLUTION */
#image1{background-color: red;}
#image2{background-color: green;}
#image3{background-color: blue;}
#viewport{width: 300px; overflow: hidden;}
#gallery-1{width: 900px; height: 420px; white-space: nowrap;}
#gallery-1 dl{float: left; margin: 0;}
/* ON HOVER, JUST TRIGGER ANIMATION WITH KEY FRAME TO PERFORM SLIDE AND PAUSE */
#viewport:hover #gallery-1{
-webkit-animation-name: slide;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: ease-in;
-webkit-animation-iteration-count: infinite;
}
/* ANIMATION ON 4S, PERCENTAGE OF THE ANIMATION HAS SAME VALUES TO MIMIC PAUSE ON ONE IMAGE */
#-webkit-keyframes slide
{
0% { transform: translateX(0); }
15% { transform: translateX(-300px); }
35% { transform: translateX(-300px); }
50% { transform: translateX(-600px); }
70% { transform: translateX(-600px); }
85% { transform: translateX(0); }
100% { transform: translateX(0); }
}
I'm trying to use ngAnimate to create transitions for my views, however i found that it needs the views to have the position property set to absolute to be able to overlap, my problem is that when I apply the position absolute, the layout loses the width and the height.
Here's how It looks like with It's default position (yes, they're on Spanish, sorry about that):
And here's how It looks like with position absolute:
and the code goes like this:
index
<div class="col-md-6 col-md-offset-1 col-sm-8 col-sm-offset-2 col-xs-12">
<div class="slideLeft" ng-view></div>
</div>
the view
<div class="panel panel-primary">
<div class="panel-heading">
<label class="fixcolor"><strong>Agregar nuevo registro</strong></label>
</div>
<div class="panel-body">
<!-- it loses the layout here when loading with ng-include -->
<div ng-switch="currentStep">
<div ng-switch-when="1">
<div class="slideLeft" ng-include="'ViewsAngular/NuevoProducto/paso1.html'">
</div>
</div>
<div ng-switch-when="2">
<div class="slideLeft" ng-include="'ViewsAngular/NuevoProducto/paso2.html'">
</div>
</div>
<div ng-switch-when="3">
<div class="slideLeft" ng-include="'ViewsAngular/NuevoProducto/paso3.html'">
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
the css
.slideLeft{
position:absolute;
}
.slideLeft.ng-leave {
-webkit-animation:slideLeftLeave 1s ease-in;
-moz-animation:slideLeftLeave 1s ease-in;
animation:slideLeftLeave 1s ease-in;
}
.slideLeft.ng-enter {
-webkit-animation:slideLeftEnter 1s ease-in;
-moz-animation:slideLeftEnter 1s ease-in;
animation:slideLeftEnter 1s ease-in;
}
#-webkit-keyframes slideLeftLeave {
from { left: 0 }
to { left: -100% }
}
#-moz-keyframes slideLeftLeave {
from { left: 0 }
to { left: -100% }
}
#keyframes slideLeftLeave {
from { left: 0 }
to { left: -100% }
}
#-webkit-keyframes slideLeftEnter {
from { left: -100% }
to { left: 0 }
}
#-moz-keyframes slideLeftEnter {
from { left: -100% }
to { left: 0 }
}
#keyframes slideLeftEnter {
from { left: -100% }
to { left: 0 }
}
I think this has something to do with the divs not expanding with dynamic content when using position absolute, but how can I do this overlapping behaviour without using absolute position?