I have some text in html that I want to animate
<div class="sofa-text inner-text">
<h1>Sofa, we have cool sofas</h1>
</div>
<div class="light-text inner-text">
<h1>our stand light is out-standing</h1>
</div>
and here's CSS
.inner-text {
display: none;
width: 100px;
height: 100px;
background-color: black;
position: absolute;
transition: 1s;
transform: translateY(200%);
animation-name: slide-up;
animation-duration: 2s;
animation-delay: .5s;
}
#keyframes slide-up{
0% {
transform: translateY(200%);
}
100% {
transform: translateY(0);
}
}
and I wanted to display this animation, after the button was clicked
let $sofaText = document.querySelector('.sofa')
let $lightText = document.querySelector('.light')
let showSofa = () => {
$sofaText.style.display = 'flex'
}
let showStand = () => {
$lightText.style.display = 'flex'
}
$sofaBtn.addEventListener('click', showSofa)
$standBtn.addEventListener('click', showStand)
However this doesn't work. I tested step by step and problem was in #keyframes. I even added -webkit but it still didn't work. I have no idea what's wrong with this
It's working you just can't see it because display:none;
function tran(){
let t = document.querySelector('.sofa-text');
t.classList.add("anim");
t.style.display = "flex";
}
.inner-text {
display:none;
width: 100px;
height: 100px;
background-color: black;
position: absolute;
transition: 1s;
transform: translateY(200%);
}
.anim{
animation-name: slide-up;
animation-duration: 2s;
animation-delay: .5s;
}
#keyframes slide-up{
0% {
transform: translateY(200%);
}
100% {
transform: translateY(0);
}
}
<button onclick="tran()">click</button>
<div class="sofa-text inner-text">
<h1>Sofa, we have cool sofas</h1>
</div>
<div class="light-text inner-text">
<h1>our stand light is out-standing</h1>
</div>
Related
<!DOCTYPE html>
<html>
<head>
<style>
#container {
position: absolute;
top: calc(50vh - 100px);
left: calc(50vw - 100px);
height: 200px;
width: 200px;
background-color: white;
border-radius: 10px;
}
.ball {
transform-origin: center;
width: 5%;
height: 5%;
margin-top: 0.8%;
border-radius: 100%;
animation: location 1.5s cubic-bezier(0.48, 0, 0.59, 0.99) 0s infinite
alternate,
size 3s linear;
animation-iteration-count: infinite;
--y: 0px;
}
.animateBackward {
animation-direction: alternate-reverse, reverse;
--y: 115%;
}
.line {
width: 10%;
height: 1.3%;
margin-top: -3%;
margin-left: 45%;
animation: lineSpin calc(3s / 4) cubic-bezier(0.48, 0, 0.59, 0.99);
animation-direction: alternate;
animation-iteration-count: infinite;
}
#keyframes location {
0% {
translate: 400% var(--y);
}
100% {
translate: 1500% var(--y);
}
}
#keyframes size {
0% {
}
25% {
transform: scale(1.5);
}
50% {
transform: scale(1);
}
75% {
transform: scale(0.5);
}
100% {
}
}
#keyframes lineSpin {
0% {
transform: scaleX(5.6);
}
100% {
transform: scaleX(0);
}
}
</style>
</head>
<body>
<div id="container"></div>
</body>
<script>
const redJump = 2.5;
const greenJump = 3;
const blueJump = -11;
const container = document.getElementById('container');
[...Array(15)].forEach((_, i) => {
const color = `rgb(${65 + redJump * i}, ${184 + greenJump * i}, ${
212 + blueJump * i
})`;
container.innerHTML += `
<div class="ball" style="animation-delay: -${
250 * i
}ms; background-color: ${color}"></div>
${
i > 0
? `<div class="line" style="animation-delay: -${
250 * i
}ms; background-color: ${color}"></div>`
: ''
}
<div class="ball animateBackward" style="animation-delay: -${
250 * (i + 1)
}ms; background-color: ${color}"></div>`;
});
</script>
</html>
Hey, I'm trying to create DNA animation and I wrote this code (using Chrome 104) and it all works fine. When I tried it in Chrom 90 I found out that the animation of the ball location keyframes is not working. I read that the translate property works only from Chrome 104 so I changed it to transform: translate() which is said in mdn that is exactly the same. But in practice is not.
How can I make my animation works properly in Chrome 90?
Hope you can help me figure out what is the problem and solve it :)
Reading in mdn and find out that the chrome version is the problem
I have an image which I need to zoom a specific point depending on which input is focused
Here's a fiddle so far
I used the attributes transform and transform-origin. It's working fine on Firefox (notice how it's moving toward the point while zooming at same time).
However on Chrome, the scale/zoom is done first, then it teleports the point. It's actually very confusing
Any idea how to make this work on Chrome ?
I experimented with putting both the transform and the transform-origin into a CSS animation and it seemed to manage to do them both at once, so avoiding the 2 step problem you saw on Chrome (tested on Edge):
#keyframes focusin {
0% {
transform: scale(1);
transform-origin: 0% 0%;
}
100% {
transform: scale(3);
transform-origin: 25% 75%;
}
}
Here's a snippet. I've put the animation time to 10s so you can see the 'journey' the paper takes when focus is on input1. It seems to be smooth, so a bit of an improvement, but it isn't 'direct' on Edge/Chrome which I guess (and it is only a guess) is to do with how the browser animates (or doesn't) transform-origin.
$("#input1").focus(function(e) {
/* $("#image").css({
"transform": "scale(3)",
"transform-origin": "25% 75%"
});*/
document.getElementById('image').style.animationName = 'focusin';
});
$("#input2").focus(function(e) {
$("#image").css({
"transform": "scale(3)",
"transform-origin": "75% 25%"
});
});
$("#input1, #input2").focusout(function(e) {
$("#image").css({
"transform": "scale(1)"
});
});
#wrapper {
width: 400px;
height: 267px;
border: 1px solid black;
overflow: hidden;
position: relative;
}
#image {
background-image: url('http://i.imgur.com/n9q7jhm.jpg');
background-size: 400px 267px;
background-position: center;
/* transition: all 1s ease; */
width: 100%;
height: 100%;
/* transform: scale(1); */
position: relative;
left: 0;
top: 0;
animation-duration: 10s;
animation-iteration-count: 1;
animation-name: none;
animation-fill-mode: forwards;
}
#keyframes focusin {
0% {
transform-origin: 0% 0%;
transform: scale(1);
}
100% {
transform-origin: 25% 75%;
transform: scale(3);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="input1">
<input type="text" id="input2">
<div id='wrapper'>
<div id='image'></div>
</div>
This is my HTML and CSS code where I want the animation to take place
.pig {
animaton-name: apple;
animation-duration: 3s;
}
#keyframe apple {
from {
top: 0px;
}
to {
right: 200px;
}
}
<div class='pig'>
<h2> About me </h2>
</div>
I'm trying to make my header move to the right, however it is not working, I am new to CSS, and I am using resources online but I can't figure out where I went wrong.
first add position : absolute to .pig class because We need the position to be able to apply top , left , right ,bottom and then edit your animaton-name to animation-name and the last one is edit your keyframe to keyframes
.pig {
animation-name: example;
animation-duration: 3s;
position: absolute;
}
#keyframes example {
from {
right: 0px;
}
to {
right: 200px;
}
}
<div class='pig'>
<h2> About me </h2>
</div>
Try this
.pig{
animation: 3s linear 0s apple;
}
#keyframes apple {
from {
transform: translateX(0px);
}
to {
transform: translateX(200px);
}
}
<div class = 'pig'>
<h2> About me </h2>
</div>
here is it it will help you move your header towards right
.pig {
animation-name: example;
animation-duration: 3s;
position: absolute;
}
#keyframes example {
from {
left: 0px;
}
to {
left: 200px;
}
}
<div class='pig'>
<h2> About me </h2>
</div>
.pig {
animation-name: apple;
animation-duration: 3s;
position: absolute;
}
#keyframes apple{
from {
left: 0px;
}
to {
left: 200px;
}
}
<div class='pig'>
<h2> About me </h2>
</div>
I am trying to make css3 spinner (loader). It works fine without .
But when I use , the css code is not loading.
See demo-
without doctype --> http://echakri.net/css-animation/witouthdoctype.html (work fine)
with doctype--> http://echakri.net/css-animation/withdotype.html (not work)
My code:
Html:
<div id="loaderw" class="loaderw">
<div class="loader1"></div>
<div class="loader2"></div>
<div class="loader3"></div>
<div class="loader4"></div>
<div class="loader5"></div>
</div>
Css:
.Loaderw {
width: 50px;
height: 40px;
text-align: center;
font-size: 10px;
float: right;
}
.Loaderw > div {
background-color: green;
height: 100%;
width: 6px;
display: inline-block;
-webkit-animation: sk-stretchdelay 1.2s infinite ease-in-out;
animation: sk-stretchdelay 1.2s infinite ease-in-out;
}
.Loaderw .loader2 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}
.Loaderw .loader3 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
.Loaderw .loader4 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.Loaderw .loader5 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
#-webkit-keyframes sk-stretchdelay {
0%, 40%, 100% { -webkit-transform: scaleY(0.4) }
20% { -webkit-transform: scaleY(1.0) }
}
#keyframes sk-stretchdelay {
0%, 40%, 100% {
transform: scaleY(0.4);
-webkit-transform: scaleY(0.4);
} 20% {
transform: scaleY(1.0);
-webkit-transform: scaleY(1.0);
}
}
<div id="loaderw" class="loaderw">
<div class="loader1"></div>
<div class="loader2"></div>
<div class="loader3"></div>
<div class="loader4"></div>
<div class="loader5"></div>
</div>
How I solve this problem?
Thanks in advance.
The HTML and CSS between the sites is different. In the page with the doctype, change the #loaderw class from lower-case to upper-case to match your CSS.
<div id="loaderw" class="loaderw">
to
<div id="loaderw" class="Loaderw">
Alternatively, you can change all of the .Loaderw classes in your CSS to .loaderw - whatever's easier. But CSS is case-sensitive, so those need to match somehow.
I am trying to recreate the following effect (click one of the colours on this page to see what I mean: http://flatuicolors.com) on an overlay when a link is clicked.
The transition is something like this: An overlay with a success message scales out and fades in, pauses and then scales out and fades out.
However, it is not producing the desired effect. What's more, the scaling is not visible at all. Any help is much appreciated.
html, body { height: 100%; }
.container {
position: relative;
margin: 0 auto; }
.container.questionnaire {
background:#f1c40f;
width: 100%;
max-width: 100%;
height: 100%;
}
.row-flex.buttons-only {
height:100%;}
.row-flex {
display: table;
width: 100%; }
.column {
box-sizing: border-box; }
.one-third-flex.column {
width: 33.3333%;
display: table-cell;
text-align: center;
vertical-align: middle;
float: none; }
.overlay {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: table;
background-color:#1abc9c;
z-index: 10;
}
h1.success-message { display: table-cell; text-align: center;
vertical-align: middle;}
.animated {
-webkit-animation-duration: 2s;
animation-duration: 2s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-timing-function: ease-out;
animation-timing-function: ease-out;
}
#-webkit-keyframes fadeOut {
0% {visibility:visible; opacity: 1;transform: scale(2);}
40% {opacity: 1;transform: scale(1.5);}
60% {opacity: 1;transform: scale(1.5);}
100% {visibility:hidden; opacity: 0;transform: scale(1);}
}
#keyframes fadeOut {
0% {visibility:visible; opacity: 1; transform: scale(2);}
40% {opacity: 1;transform: scale(1.5);}
60% {opacity: 1;transform: scale(1.5);}
100% {visibility:hidden;opacity: 0; transform: scale(1);}
}
.fadeOut {
-webkit-animation-name: fadeOut;
animation-name: fadeOut;
}
<body>
<div class="overlay animated fadeOut"><h1 class="success-message">Success</h1></div>
<div class="container questionnaire">
<div class="row row-flex buttons-only">
<div class="one-third-flex column"></div>
<div class="one-third-flex column" style="background-color: #f4f4f4;">
<div role="button" class="ico-btn btn-settings-lg">CLICK
</div>
</div>
<div class="one-third-flex column"></div>
</div>
</div>
</body>
Well, I hope this answer may help you.
As I thought that was an interesting effect (created with flash), I have worked a bit creating it from scratch with css3 and jquery. It was easier for me to do my code insteed of trying to modify yours so that’s why It maybe not be usefull for You but maybe it may be for other users.
The html is simple:
<div class="square ">
</div>
<div class="effect ">
<div class="text">TEXT HERE</div>
</div>
Where square is the area to click and effect is the container of the animation, which is a div with 0 height and width placed at the center of the window in case you want to add more animations (as to make it “grow” or shrink).
With, also, some simple jquery:
$('. square).click(function () {
$('. effect).addClass("animation");
$('.text').addClass("text-effect");
setTimeout(function () {
$('. effect).removeClass("animation");
$('.text').removeClass("text-effect");
}, 1500);
});
to add a class to effect and text on click and remove it after animation is done
Then after some basic CSS styles I made the animation for effect:
.animation {
animation-name: background;
animation-duration: 1.5s;
animation-timing-function: linear;
animation-delay: 0s;
animation-iteration-count: 1;
}
#keyframes background {
0% {height:100%; width:100%; opacity:1}
80% {height:100%; width:100%; opacity:1}
99.999% {height:100%; width:100%; opacity:0}
100% {height:0; width:0; opacity:0}
}
And for the text I have just used a transition:
.text {
background-color:rgba(255,255,255,0.6);
width:100%;
text-align:center;
font-size:50px;
color:#fff;
font-weignt:bold;
text-shadow: 1px 1px 0 #000000;
font-family:arial;
padding:20px 0;
transition:all 0.2s linear;
position:absolute;
top:50%;
transform: translateY(-50%);
transition:all 0.2s linear;
}
.text-effect {
padding:10px 0;
font-size:40px;
}
All toguether and adding 8 squares with different colors:
JSFIDDLE
and, as I wrote above, the background fading and shrinking just with
#keyframes background {
0% {height:100%; width:100%; opacity:1}
80% {height:100%; width:100%; opacity:1}
100% {height:0; width:0; opacity:0}
}
JSFIDDLE2