I'm trying to move an img in a 3d space by using transform: translateZ().
here is a picture of what i have currently.
im trying to move the img icons around the box.
Here is what ive tried:
Using transform: translateZ(100px) in the id selectors for each img.
Using .box img:nthchild(7) {translateZ(100px)}.
Tried adding perspective to the .box class.
#animated-box {
position: absolute;
left: 67%;
top: 35%;
height: 300px;
width: 300px;
perspective: 1000px;
perspective-origin: 50% 50%;
cursor: pointer;
}
.box {
transform-style: preserve-3d;
width: 250px;
height: 250px;
position: relative;
animation: rotate 60s infinite;
z-index: 100;
}
.box div {
position: absolute;
width: 250px;
height: 250px;
opacity: 1;
background-color: #272727b2;
border: 1px solid #55FFEB;
box-shadow: inset 0 0 20px 5px rgb(85, 255, 235);
transition: all 1s ease;
z-index: 99;
}
#html-png {
top: 40%;
left: 60%;
height: 80px;
width: auto;
animation: crazy 45s infinite;
transform: translateY(1000px);
}
#js-png {
position: absolute;
top: 55%;
left: 35%;
height: 70px;
width: auto;
animation: crazy 45s infinite;
}
#css-png {
left: 10%;
top: 15%;
position: absolute;
height: 80px;
width: auto;
animation: crazy 45s infinite;
}
#boot-png {
left: 10%;
top: -17%;
position: absolute;
height: 80px;
width: auto;
animation: crazy 45s infinite;
}
#git-png {
left: 10%;
top: -17%;
position: absolute;
height: 80px;
width: auto;
animation: crazy 45s infinite;
}
#box-text {
position: relative;
top: 25%;
left: -20%;
width: 500px;
background-color: none;
color: white;
font-size: 20px;
opacity: 0;
transition: all 1s ease;
letter-spacing: .5px;
}
<!-- animated floating box -->
<section id="animated-box">
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<img id="html-png" src="imgs/html5.png" alt="">
<img id="css-png" src="imgs/css.png" alt="">
<img id="js-png" src="imgs/javascript.png" alt="">
<img id="boot-png" src="imgs/boot.png" alt="">
<img id="git-png" src="imgs/git.png" alt="">
</div>
<div id="box-text">Click cube to see the code running this page</div>
</section>
[![enter image description here][1]][1]
any advice would be welcome, thanks in advance.
Related
I want to create an animation in HTML, CSS where 3 images will be on each other. At that time there is a text says car and then all images will be separate and each image has text bottom of them saying body, tyres, engine. Any resource or how to do this type of animation?
I hope this will explain what I'm looking for.
.container {
position: absolute;
margin-left: auto;
margin-right: auto;
top: 0;
left: 45%;
height: 200px;
width: 200px;
}
.image-1 {
position: absolute;
top: 0;
left: 0;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 100%;
animation: moveltf 1s ease-in-out;
}
.image-2 {
position: absolute;
top: 0;
left: 0;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 100%;
}
.image-3 {
position: absolute;
top: 0;
left: 0;
margin-left: auto;
margin-right: auto;
width: 100%;
height: 100%;
animation: movertf 1s ease-in-out;
}
.image-1 {
animation-direction: normal;
animation-delay: 2s;
}
.image-3 {
animation-direction: reverse;
animation-delay: 2s;
}
#keyframes moveltf {
0% {
top: 0;
left: 0;
}
100% {
left: 100%;
}
}
#keyframes movertf {
0% {
top: 0;
left: 0;
}
100% {
right: 100%;
}
}
<div class="container">
<div class="image-1">
<img src="https://via.placeholder.com/50">
<p class="text">Image 1 </p>
</div>
<div class="image-2">
<img src="https://via.placeholder.com/50/ffff00">
<p class="text">Image 2</p>
</div>
<div class="image-3">
<img src="https://via.placeholder.com/50/ff00ff">
<p class="text">Image 3</p>
</div>
</div>
I'm trying to make a 'dot' orbit around another object (circle) but due to the z-index the dot always appears above the circle it is meant orbiting around.
CodePen link: https://codepen.io/moy/pen/ROVZXd?editors=1100
Ideally the 2nd half of the animation would take place behind the object so it's not seen until it comes out the other side - is that possible?
I thought about fading out the object that is moving around but I don't think that would give a smooth/masked effect?
A bit stuck as to how I'd mask this area as I can't see a way the CSS would know it's meant to be hidden. I thought maybe I could change the z-index 50% though the animation it and reset it at 0%/100% but that doesn't appear to do anything.
Any ideas? Thanks in advance!
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 30px auto;
position: relative;
width: 100px;
z-index: 20;
}
.orbit {
border: 2px #eee transparent;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
z-index: 10;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
z-index: 10;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg); z-index: 20;
}
50% {
z-index: -20;
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg); z-index: 20;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
I seem to have solved this by adding a negative z-index to an animation applied to the parent .orbit
Link: https://codepen.io/moy/pen/wZdpRw?editors=1100
I initially applied this at 50% through the animation as that should be the furthest away the dot is before it comes back behind the larger circle. However this didn't work, setting it on 100% did work. Not entirely sure why but it seems to work!
The initial issue was due to the fact that you are applying z-index to the parent element and doing so it will impossible to make the child to move behind it (Why elements with any z-index value can never cover its child?) thus changin z-index is useless
Even if you remove the z-index from the parent you still have the transform that is also creating a stacking context making impossible to the child element to move behind so you cannot make the .moon to move behind the .earth.
The only way to do it (like you already noticed) is to remove z-index from the .earth to avoid the earth creating a stacking context and animate z-index of orbit to make the orbit AND the moon moving behind the earth (not only the moon).
Add some coloration to better see this:
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 60px auto;
position: relative;
width: 100px;
}
.orbit {
animation: hide ease-in-out infinite;
animation-duration: 2s;
background:red;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg);
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg);
}
}
#keyframes hide {
0% {
z-index: 20;
}
100% {
z-index: -20;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
Now if you add back z-index to earth it will stop working because of the stacking context:
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 60px auto;
position: relative;
width: 100px;
z-index:2;
}
.orbit {
animation: hide ease-in-out infinite;
animation-duration: 2s;
background:red;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg);
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg);
}
}
#keyframes hide {
0% {
z-index: 20;
}
100% {
z-index: -20;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
You can try key-framing the opacity:
.earth {
background: white;
border: 1px solid black;
border-radius: 50%;
display: block;
height: 100px;
margin: 30px auto;
position: relative;
width: 100px;
z-index: 20;
}
.orbit {
border: 2px #eee transparent;
border-radius: 50%;
height: 140px;
margin: auto;
position: absolute;
top: -20px;
left: -20px;
transform: rotateZ(60deg) rotateY(60deg);
transform-style: preserve-3d;
width: 140px;
z-index: 10;
}
.orbit .moon {
animation: move ease-in-out infinite;
animation-duration: 2s;
background: black;
border-radius: 50%;
height: 15px;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 15px;
z-index: 10;
}
#keyframes move {
0% {
transform: rotateZ(-90deg) translateX(70px) rotateZ(90deg) rotateY(-70deg); opacity: 1;
}
56% {
opacity: 1;
}
58% {
opacity: 0;
}
77% {
opacity: 0;
}
78% {
opacity: 1;
}
100% {
transform: rotateZ(270deg) translateX(70px) rotateZ(-270deg) rotateY(-70deg); opacity: 1;
}
}
<div class="earth">
<div class="orbit">
<div class="moon"></div>
</div>
</div>
Only one of my planets is clickable in my animation, my intention with the program is for all of the planets to be clickable, and when clicked, take you to the corresponding page. The planet that is clickable is Venus which is the outermost planet currently. Does anyone know why this problem is occurring?
#earthOrbit {
border: dashed 3px lightskyblue;
position: absolute;
top: 50%;
left: 75%;
margin-top: -125px;
margin-left: -125px;
height: 200px;
width: 200px;
border-radius: 100%;
animation: spin 45s linear infinite;
}
#earth {
position: absolute;
top: 50%;
left: -10%;
margin-top: -40px;
animation: spin 40s linear infinite;
}
#marsOrbit {
border: dashed 3px lightcoral;
position: absolute;
top: 50%;
left: 75%;
margin-top: -175px;
margin-left: -175px;
height: 300px;
width: 300px;
border-radius: 100%;
animation: spin 50s linear infinite;
}
#mars {
position: absolute;
top: 50%;
left: -6%;
margin-top: -40px;
animation: spin 50s linear infinite;
}
#jupiterOrbit {
border: dashed 3px beige;
position: absolute;
top: 50%;
left: 75%;
margin-top: -225px;
margin-left: -225px;
height: 400px;
width: 400px;
border-radius: 100%;
animation: spin 55s linear infinite;
}
#jupiter {
position: absolute;
top: 50%;
left: -4.5%;
margin-top: -40px;
animation: spin 20s linear infinite;
}
#venusOrbit {
border: dashed 3px sandybrown;
position: absolute;
top: 50%;
left: 75%;
margin-top: -275px;
margin-left: -275px;
height: 500px;
width: 500px;
border-radius: 100%;
animation: spin 60s linear infinite;
}
#venus {
position: absolute;
top: 50%;
left: -4.5%;
margin-top: -40px;
animation: spin 20s linear infinite;
}
img {
height: 45px;
width: 45px;
}
<div id="sun"></div>
<div id="earthOrbit">
<img src="earth.png" alt="earth" id="earth">
</div>
<div id="jupiterOrbit">
<img src="jupiter.png" alt="jupiter" id="jupiter">
</div>
<div id="marsOrbit">
<img src="mars.png" alt="mars" id="mars">
</div>
<div id="venusOrbit">
<img src="venus.png" alt="venus" id="venus">
</div>
Try adding different z-indexs to the orbits to create a layering affect... highest z-index for the inner orbit and then lower as you go out. I started with a z-index of 50 on earth and then down to 20 with venus.
You can now click on each one individually.
#earthOrbit {
border: dashed 3px lightskyblue;
position: absolute;
top: 50%;
left: 75%;
margin-top: -125px;
margin-left: -125px;
height: 200px;
width: 200px;
border-radius: 100%;
animation: spin 45s linear infinite;
z-index: 50;
}
#earth {
position: absolute;
top: 50%;
left: -10%;
margin-top: -40px;
animation: spin 40s linear infinite;
}
#marsOrbit {
border: dashed 3px lightcoral;
position: absolute;
top: 50%;
left: 75%;
margin-top: -175px;
margin-left: -175px;
height: 300px;
width: 300px;
border-radius: 100%;
animation: spin 50s linear infinite;
z-index: 40;
}
#mars {
position: absolute;
top: 50%;
left: -6%;
margin-top: -40px;
animation: spin 50s linear infinite;
}
#jupiterOrbit {
border: dashed 3px beige;
position: absolute;
top: 50%;
left: 75%;
margin-top: -225px;
margin-left: -225px;
height: 400px;
width: 400px;
border-radius: 100%;
animation: spin 55s linear infinite;
z-index: 30;
}
#jupiter {
position: absolute;
top: 50%;
left: -4.5%;
margin-top: -40px;
animation: spin 20s linear infinite;
}
#venusOrbit {
border: dashed 3px sandybrown;
position: absolute;
top: 50%;
left: 75%;
margin-top: -275px;
margin-left: -275px;
height: 500px;
width: 500px;
border-radius: 100%;
animation: spin 60s linear infinite;
z-index: 20;
}
#venus {
position: absolute;
top: 50%;
left: -4.5%;
margin-top: -40px;
animation: spin 20s linear infinite;
}
img {
height: 45px;
width: 45px;
}
<div id="sun"></div>
<div id="earthOrbit">
<img src="earth.png" alt="earth" id="earth">
</div>
<div id="jupiterOrbit">
<img src="jupiter.png" alt="jupiter" id="jupiter">
</div>
<div id="marsOrbit">
<img src="mars.png" alt="mars" id="mars">
</div>
<div id="venusOrbit">
<img src="venus.png" alt="venus" id="venus">
</div>
Whenever I hover on the first image, it moves to a different location. That is supposed to happen. But it comes back to it's original spot after un-hover. I need it to stay in the end location. If you understood that, can you help? Thanks in advance.`
I tried to have the code animation infinite, but that doesn't seem to work.
<html style="overflow: hidden;">
<meta name="viewport" content="width=device-width">
<head>
<script>
window.start();
function start(){
alert("This site is secure with SITELOCK TM. If this Website is hacked, the record will be loggled, and will be reported.");
console.log("This site is secure with SITELOCK TM. If this Website is hacked, the record will be loggled, and will be reported.")
}
</script>
<style>
#keyframes slide{
0%{
width: 50px;
}
100%{
width: 300px;
}
}
#keyframes fly{
0%{
top: 25;
left: 17;
width: 20;
}
100%{
top: 157;
left: 30;
}
}
#keyframes fade{
from{opacity: 0;}
to{opacity: 1;}
}
#keyframes fade2{
from{opacity: 0;}
to{opacity: 1;}
}
#keyframes goaway{
0%{
opacity: 1;
}
100%{
opacity: 0;
}
}
.nav:hover{
animation: slide 2s forwards;
}
.nav:hover > center > #home{
animation: fade2 2s forwards;
}
.nav:hover > center > #about{
animation: fade 2s forwards;
}
.nav:hover > #rocket{
animation: fly 2s forwards;
}
.nav:hover > #title{
animation: fade 7s forwards;
}
.nav:hover > center > #shop{
animation: fade 3s forwards;
}
.nav:hover > #menu_mark{
animation: goaway 1s forwards;
}
#image1:hover{
animation: move1 0.5s infinite;
}
#keyframes move1{
0%{
width: 160px;
top: 70px;
left: 200px;
}
50%{
width: 180px;
top: 50px;
left: 400px;
}
100%{
width: 200px;
top: 30px;
left: 600px;
}
}
#image1:hover ~ #image2{
animation: move2 0.5s infinite;
}
#keyframes move2{
0%{
left: 400px;
width: 180px;
top: 50px;
}
50%{
left: 600px;
width: 200px;
top: 30px;
}
100%{
width: 180px;
top: 50px;
left: 820px;
}
}
#image1: ~ #image3{
}
#image1:hover ~ #image4{
}
#image1:hover ~ #image5{
}
</style>
<script>
</script>
</head>
<link href="https://fonts.googleapis.com/css?family=Luckiest+Guy" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Thasadith" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Fjalla+One" rel="stylesheet">
<body style=" align-content: center; margin: 0; padding: 0; background-color: #404040; overflow-y: hidden;">
<div class="elements">
<img src="Image%201.png" id="image1" style="width: 160px; position: absolute; top: 70px; left: 220px; border-radius: 10px;">
<img src="Image%202.png" id="image2" style="width: 180px; position: absolute; top: 50px; left: 400px; border-radius: 10px;">
<img src="Image%203.png" id="image3" style="width: 200px; position: absolute; top: 30px; left: 600px; border-radius: 10px;">
<img src="Image%204.png" id="image4" style="width: 180px; position: absolute; top: 50px; left: 820px; border-radius: 10px;">
<img src="Image%205.png" id="image5" style="width: 160px; position: absolute; top: 70px; left: 1015px; border-radius: 10px;">
</div>
<div class="nav" style="background-color: #282829; height: 800px; width: 50px; box-shadow: 10px 0px 10px rgba(0, 0, 0, 0.4); margin-bottom: 10px; position: sticky; float: left;" >
<span id="title" style="display: inline-block; font-family: Thasadith; color: white; font-size: 40px; position: absolute; top: 150; left: 60px; opacity: 0;">MONOSPACE</span>
<center><span id="home" style="display: inline-block; padding-bottom: 25px; font-family: Fjalla One; color: white; font-size: 20px; padding-top: 250px; opacity: 0;">HOME</span><br>
<span id="about" style="display: inline-block; padding-bottom: 25px; font-family: Fjalla One; color: white; font-size: 20px; opacity: 0;">ABOUT</span><br>
<span id="shop" style="display: inline-block; padding-bottom: 25px; font-family: Fjalla One; color: white; font-size: 20px; opacity: 0;">SHOP</span><br></center>
<img id="menu_mark" src="LogoMakr_6Pr2go.png" style="width: 25px; position: absolute; top: 300px; left: 12.5px;">
<img id="rocket" src="LogoMakr_9Pl0y8.png" style="color: white; position: absolute; top: 25; left: 17; width: 20;">
</div>
</body>
</html>
You need two things. Firstly use forwards in the animation rather than infinite which is going to infinitely loop your animation. Secondly you need to maintain state. As soon as you mouse away that end state of the animation is lost and will repeat on re-hover. To avoid this use javascript to add a class on hover, this will handle the state for you.
const image = document.getElementById("image1");
const onHover = (e) => {
event.target.classList.add("hovered");
console.log('image hovered');
event.target.removeEventListener("mouseenter", onHover)
};
image.addEventListener("mouseenter", onHover)
#image1 {
width: 100px;
height: 100px;
background: blue
}
#image1.hovered {
animation: move1 0.5s forwards;
}
#keyframes move1{
0%{
width: 160px;
top: 70px;
left: 200px;
}
50%{
width: 180px;
top: 50px;
left: 400px;
}
100%{
width: 200px;
top: 30px;
left: 600px;
}
}
<div id="image1">
</div>
Try adding a timing for your animation:
.nav:hover > center > #home{ animation: fade2 2s ease-in-out forwards; }
I never use to/from, I always use 0%/100% you can do more things in that way.
Tell me if it works because I use my keyframes like this.
I was wondering if it was possible to use jquery window.resize() to ensure the two donuts positioning never collides with the home text in the middle. I'm not sure how to link the x and y of the window size to change the top/left and bottom/right positioning values.
Or is there a way I could decrease the width and height of the donuts on window resize?
Any help would be appreciated!
html, body {
margin: 0;
}
#container {
width: 100vw;
height: 100vh;
background-color: pink;
display: flex;
align-items: center;
overflow: hidden;
position: relative;
}
#donut img,
#donut2 img {
width: 500px;
height: 500px;
}
#donut {
width: auto;
height: auto;
position: absolute;
animation: donut 2s;
animation-fill-mode: forwards;
}
#keyframes donut {
0% {
left: -20%;
top: -20%;
transform: translateZ(-100px);
}
100% {
left: -5%;
top: -5%;
transform: translateZ(100px);
}
}
#donut2 {
width: auto;
height: auto;
position: absolute;
animation: donut2 2s;
animation-fill-mode: forwards;
}
#keyframes donut2 {
0% {
right: -20%;
bottom: -20%;
transform: translateZ(-100px);
}
100% {
right: -5%;
bottom: -5%;
transform: translateZ(-100px);
}
}
#homeText {
width: 100%;
height: auto;
text-align: center;
font-size: 30px;
}
<div id="container">
<div id="donut">
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a5/Glazed-Donut.jpg">
</div>
<div id="homeText">
<p>
Reward Points
</p>
<p>Get Your Daily Sweet Rewards</p>
</div>
<div id="donut2">
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a5/Glazed-Donut.jpg">
</div>
</div>
Please Try This. I think this should be work:-
#container {
width: 100vw;
height: 100vh;
background-color: pink;
display: flex;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}
#donut { width:30vw; }
#donut2 { width:30vw; }
#donut2 img, #donut img {
width: 100%;
max-width:100%;
height:auto;
}
#donut {
position: absolute;
animation: donut 2s;
animation-fill-mode: forwards;
}
#keyframes donut {
0% {
left: -5%;
top: -5%;
transform: translateZ(-100px);
}
100% {
left: 5%;
top: 5%;
transform: translateZ(100px);
}
}
#donut2 {
position: absolute;
animation: donut2 2s;
animation-fill-mode: forwards;
}
#keyframes donut2 {
0% {
right: -5%;
bottom: -5%;
transform: translateZ(-100px);
}
100% {
right: 5%;
bottom: 5%;
transform: translateZ(-100px);
}
}
#homeText {
width: 25vw;
height: auto;
text-align: center;
font-size: 30px;
}