I currently have the following HTML and CSS which creates the effect of flipping between the content of two divs.
How I can expand on this to flip between 4 (or more) divs?
I was thinking either of these approaches might be the way forward but I'm not sure how to implement them!
pause the animations at rotateX(90deg) then start a second set of animations;
or change the content of the divs when they are at rotateX(90deg).
HTML
<div class="flip1">
FLIP 1<br />
FLIP 1<br />
FLIP 1<br />
FLIP 1<br />
</div>
<div class="flip2">
FLIP 2<br />
FLIP 2<br />
FLIP 2<br />
FLIP 2<br />
</div>
CSS
div {
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function:linear;
-webkit-backface-visibility: hidden;
color: blue;
font-family: Helvetica,Arial,sans-serif;
font-weight: bold;
padding: 20px;
position: absolute;
}
#-webkit-keyframes flip1 {
from { -webkit-transform: rotateX(0deg); }
to { -webkit-transform: rotateX(360deg); }
}
div.flip1 {
-webkit-animation-name: flip1;
}
#-webkit-keyframes flip2 {
from { -webkit-transform: rotateX(-180deg); }
to { -webkit-transform: rotateX(180deg); }
}
div.flip2 {
-webkit-animation-name: flip2;
}
I got there in the end with a touch of JavaScript.
The HTML was:
<div class="flippable" id="flip1">
FLIP 1<br />
FLIP 1<br />
FLIP 1<br />
FLIP 1<br />
</div>
<div class="flippable" id="flip2">
FLIP 2<br />
FLIP 2<br />
FLIP 2<br />
FLIP 2<br />
</div>
<div class="flippable" id="flip3">
FLIP 3<br />
FLIP 3<br />
FLIP 3<br />
FLIP 3<br />
</div>
<div class="flippable" id="flip4">
FLIP 4<br />
FLIP 4<br />
FLIP 4<br />
FLIP 4<br />
</div>
<script>
$(document).ready(function() {
flip_flippables();
setInterval(flip_flippables, $('.flippable').length*2000);
function flip_flippables(){
$('.flippable').each(function(index) {
setTimeout(function(thisObj) { thisObj.addClass("flippedforward"); }, index*2000, $(this));
$(this).removeClass("flippedforward");
});
}
});
</script>
The CSS was:
.flippable {
-webkit-transform: rotateX(-90deg);
color: blue;
font-family: Helvetica,Arial,sans-serif;
font-weight: bold;
padding: 20px;
position: absolute;
}
.flippedforward {
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: 1;
-webkit-animation-name: flip;
-webkit-transform: rotateX(90deg);
}
#-webkit-keyframes flip {
0% { -webkit-transform: rotateX(-90deg); }
25% { -webkit-transform: rotateX(0deg); }
75% { -webkit-transform: rotateX(0deg); }
100% { -webkit-transform: rotateX(90deg); }
}
Related
I tried to rotate an animated font arrow when the window reached a min/max size, but when the rotate takes place the animation stops, also just for testing I tried replacing transform: rotate(90deg) to transform: rotate(0deg) which maintains the same arrow's direction but it causes to stop the animation too. The issue is with transform: rotate() and it can be easily tested by inspecting the element and activating/deactivating it in the browsers developer tools.
An easy way to bypass this can be using two <p> each one with an arrow in different direction and with vertical and horizontal animation each, and using display: none; to alternate between them when the min/max size switches, but what I want is to know why this is happening and how to solve this using this approach
.text-center {
text-align: center;
}
.lnr-x3 {
font-size: 2.4rem;
}
#media (max-width: 991px) {
#catalogArrow_h {
transform: rotate(90deg) !important;
transform-origin: center !important;
}
}
.animated-h {
text-decoration: none;
outline-style: none;
-webkit-animation: movingHorizontally 1.7s ease-in-out infinite;
animation: movingHorizontally 1.7s ease-in-out infinite;
}
#keyframes movingHorizontally {
0% {
transform: translateX(0px);
-webkit-transform: translateX(0px);
}
50% {
transform: translateX(-10px);
-webkit-transform: translateX(-10px);
}
100% {
transform: translateX(0px);
-webkit-transform: translateX(0px);
}
}
#-webkit-keyframes movingHorizontally {
0% {
transform: translateX(0px);
-webkit-transform: translateX(0px);
}
50% {
transform: translateX(-10px);
-webkit-transform: translateX(-10px);
}
100% {
transform: translateX(0px);
-webkit-transform: translateX(0px);
}
}
<!-- Font Icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" type="text/css">
<link rel="stylesheet" href="https://cdn.linearicons.com/free/1.0.0/icon-font.min.css">
<div class="col-12">
<p class="text-center pt-3 px-5">
<span id="catalogArrow_h" class="lnr lnr-x3 lnr-arrow-right fas animated-h"></span>
</p>
</div>
Why does this happen
The transform property is "shared" for many transform functions and css doesn't combine any property's values.
Because your animation is made with transform: translateX(..), adding transform: rotate(..) will overwrite the property's value, not combine them. I.e. the resulting style is transform: rotate(..), not transform: translateX(..) rotate(..).
It would be the same if you were animating the box-shadow and then wanted an inset box-shadow too, it would overwrite one with the other. Or more simply - if you have .box { color: red; color: blue; } css will choose the last value (blue) to apply to the color property.
If there were css properties rotate: 90deg and translate: 4px (there are but not widely supported), then your animation would work, because the translate animation would be applying to a different property than the rotation, not overwriting one that is essentially shared amongst many transform functions.
Ways around it
There are many ways around this problem.
You can set the translate or rotate on the parent element
<div class="rotate-90">
<span class="translate-animate"></span>
</div>
You can add the rotate to your translate animation properties:
#keyframes movingHorizontallyRotated {
0%, 100% { transform: translateX(0px) rotate(90deg); }
50% { transform: translateX(-10px) rotate(90deg); }
}
You can animate a different property to translate the element:
#keyframes movingHorizontally {
0%, 100% { padding: 5px 10px 5px 0px; }
50% { padding: 5px 0px 5px 10px; }
}
You can use/make an already rotated arrow if your framework/ assets provides one.
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>
When hovering the image ,image moves to the left,I want it to stay at the new position where it moved to, while moving the pointer away.
Thanks in advance
.object{
position:absolute;
}
.bird{
top: 50%;
left: 64%;
}
#twit:hover .move{
transform: translate(-350px,0) rotate(-360deg);
transition:all 2s linear;
}
<div id="twit">
<div class="object bird move">
<img width="50px" height="50px" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0rasMS9P_knjCI0jPS2S3EavRVR57YSoOJSomU3tcmaxV_zom5cZWOg">
<b>Welcome Home</b>
</div>
</div>
What you want can be achieve, but you need to remove your :hover selector and use that as css animation. Another way is using jQuery mouseenter event.
Using CSS animation and removing hover selector.
.object{
position:absolute;
}
.bird{
top: 50%;
left: 64%;
}
.move{
-webkit-animation:mv 2s;
animation-fill-mode:forwards;
}
#-webkit-keyframes mv{
from{
transform: translate(0,0) rotate(0deg);
}
to{
transform: translate(-350px,0) rotate(-360deg);
}
}
<div id="twit">
<div class="object bird move">
<img width="50px" height="50px" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0rasMS9P_knjCI0jPS2S3EavRVR57YSoOJSomU3tcmaxV_zom5cZWOg">
<b>Welcome Home</b>
</div>
</div>
Another way is using jQuery mouseenter event, which performs same css animation, but stop your element at new position.
$(document).ready(function(){
$("#twit").on("mouseenter",function(){
$("#twit > .object").addClass("nwmv");
});
});
.object{
position:absolute;
}
.bird{
top: 50%;
left: 64%;
}
.nwmv{
-webkit-animation:mvv 2s;
animation-fill-mode:forwards;
}
#-webkit-keyframes mvv{
from{
transform: translate(0,0) rotate(0deg);
}
to{
transform: translate(-350px,0) rotate(-360deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="twit">
<div class="object bird move">
<img width="50px" height="50px" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0rasMS9P_knjCI0jPS2S3EavRVR57YSoOJSomU3tcmaxV_zom5cZWOg">
<b>Welcome Home</b>
</div>
</div>
Using Javascript,
var b = document.getElementById("twit");
b.onmouseenter = function mv(){
var a = document.querySelector(".move");
a.style.transition = "2s ease";
a.style.transform = "translate(-350px,0) rotate(-360deg)";
}
.object{
position:absolute;
}
.bird{
top: 50%;
left: 64%;
}
<div id="twit">
<div class="object bird move">
<img width="50px" height="50px" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0rasMS9P_knjCI0jPS2S3EavRVR57YSoOJSomU3tcmaxV_zom5cZWOg">
<b>Welcome Home</b>
</div>
</div>
I asked this question. Here another issue to complement that:
I have an image and header in my html
HTML:
<div class="col-md-4 no-underline-hover">
<a class="rightImg">
<img class="img-responsive icon-img homepage-icon" src="{{asset('assets/img/homepage/icons/1.png')}}" alt="Greece-1173 - Temple of Athena by Dennis Jarvis, on Flickr">
<h3 class = "gray-color homepage-icon-detail">perfume </h3>
</a>
</div>
CSS:
.homepage-icon:hover {
transform: scale(1.03, 1.03);
}
.homepage-icon {
transition: 0.3s ease;
}
.homepage-icon:hover +.homepage-icon-detail {
color: hsl(288, 63%, 28%);
transform: scale(1.1);
}
h3.homepage-icon-detail:hover {
transform: scale(1.1);
color: hsl(288, 63%, 28%);
}
h3.homepage-icon-detail:hover + .homepage-icon{
transform: scale(1.03, 1.03);
}
Whenever I hover homepage-icon , h3's color is changing. What I want to change is the icon size when I hover h3. Any suggestion?
This should do what you want
h3:hover + .homepage-icon{
transform: scale(1.03, 1.03);
}
homepage-icon:hover ~ h3{
color:white;
}
I think You have to do this way:
h3:hover .homepage-icon{
transform: scale(1.03, 1.03);
}
and
homepage-icon:hover h3{
color:white;
}
I have made the marquee completely using css. Here is the jsfiddle of it. But I want the text to move from bottom to up. Currently it is moving left to right. How can I make it move from bottom to up ?
CSS
/* define the animation */
#-webkit-keyframes marquee {
0% { -webkit-transform: translate(0, 0); }
100% { -webkit-transform: translate(-100%, 0); }
}
#-moz-keyframes marquee {
0% { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}
/* define your limiting container */
.marquee {
border: solid 2px;
white-space: nowrap;
overflow: hidden;
box-sizing: border-box;
}
/* this is the tray moving around your container */
.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee 15s linear infinite; /* here you select the animation */
-webkit-animation: marquee 15s linear infinite; /* here you select the animation */
}
/* pause the animation on mouse over */
.marquee span:hover {
animation-play-state: paused;
-webkit-animation-play-state: paused;
}
HTML
<p class="marquee">
<span>
Hey! What's up? <br />
Second Line <br />
Third Line <br />
Fourth Line <br />
Fifth Line <br /
</span>
Remove padding-left: 100%; and tweak the transform like
#keyframes marquee {
0% { -webkit-transform: translate(0, 0); }
100% { -webkit-transform: translate(0, -100%); }
}
Demo
Explanation : 0, 0 means x and y axis respectively, so instead of using (0,0) to (-100%,0) which is nothing but you are moving the text on x axis, take the -100% to the y axis and get rid of padding-left: 100%; in .marquee span
As you commented that you wanted to show 1-2 lines on load and then start scrolling, so provide some height to the container element and use padding-top or you can use margin-top for your span element like
Demo 2
Also, #harry has suggested similar in his comment, take a look