HTML CSS Flying Image on Icon click (Easter egg) - html

I'm build a portfolio page with cargo site. I'm not an developer and I don't have really a good Idea about HTML & CSS. I have tried some research on the Web for this but found nothing that would help me. Maybe some of you could help me.
I just wanted to build an Easter egg on my site, it should work like this: on a icon click it should trigger this css animation. The code for this animation is directly from cargo but it works only as an animation right away when you enter the page. How can I hide it behind a Icon trigger.
https://support.cargo.site/Make-an-Image-Fly-Across-the-Screen
<div class="flier">{image 1}</div>
.flier {
pointer-events: none;
}
.flier {
animation: fly 50s linear infinite;
pointer-events: none !important;
top: 0;
left: 0;
transform: translateX(-120%) translateY(-120%) rotateZ(0);
position: fixed;
animation-delay: 1s;
z-index: 999999;
}
/* Keyframe values control where the element will begin
and end its trajectory across the screen. Each rule
represents a path the element follows across the screen. */
#keyframes fly {
98.001%, 0% {
display: block;
transform: translateX(-200%) translateY(100vh) rotateZ(0deg)
}
15% {
transform: translateX(100vw) translateY(-100%) rotateZ(180deg)
}
15.001%, 18% {
transform: translateX(100vw) translateY(-30%) rotateZ(0deg)
}
40% {
transform: translateX(-200%) translateY(3vh) rotateZ(-180deg)
}
40.001%, 43% {
transform: translateX(-200%) translateY(-100%) rotateZ(-180deg)
}
65% {
transform: translateX(100vw) translateY(50vh) rotateZ(0deg)
}
65.001%, 68% {
transform: translateX(20vw) translateY(-200%) rotateZ(180deg)
}
95% {
transform: translateX(10vw) translateY(100vh) rotateZ(0deg)
}
}

Step1: Add the button in HTML
<button onClick="animEgg()">
<i class="fas fa-egg"></i> <span id='toggleText'>Start</span>
</button>
Step2: Your code which has an image to be animated
<div class="flier">
<img src="https://picsum.photos/200/300" />
</div>
Step3: Add css
.flier > * {
/* Adjust animation duration to change the element’s speed */
pointer-events: none !important;
top: 0;
left: 0;
transform: translateX(-120%) translateY(-120%) rotateZ(0);
position: fixed;
animation-delay: 1s;
z-index: 999999;
}
.flier img.anim{
animation: fly 50s linear infinite;
}
/* Keyframe values control where the element will begin
and end its trajectory across the screen. Each rule
represents a path the element follows across the screen. */
#keyframes fly {
98.001%, 0% {
display: block;
transform: translateX(-200%) translateY(100vh) rotateZ(0deg)
}
15% {
transform: translateX(100vw) translateY(-100%) rotateZ(180deg)
}
15.001%, 18% {
transform: translateX(100vw) translateY(-30%) rotateZ(0deg)
}
40% {
transform: translateX(-200%) translateY(3vh) rotateZ(-180deg)
}
40.001%, 43% {
transform: translateX(-200%) translateY(-100%) rotateZ(-180deg)
}
65% {
transform: translateX(100vw) translateY(50vh) rotateZ(0deg)
}
65.001%, 68% {
transform: translateX(20vw) translateY(-200%) rotateZ(180deg)
}
95% {
transform: translateX(10vw) translateY(100vh) rotateZ(0deg)
}
}
Step4: Add JS (Hopefully jQuery library is linked)
function animEgg(){
$(".flier img").toggleClass('anim');
if($("#toggleText").text() == 'Start')
$("#toggleText").text('Stop');
else
$("#toggleText").text('Start');
}

All the constituent parts are there apart from triggering it.
Just need to trigger the animation by maybe adding a class specifically for the animation property... something like this?
https://codepen.io/badgerswork/pen/wvzvWdW
let elem = document.querySelector('.flier')
let trigger = document.querySelector('.activate')
trigger.addEventListener('click', function() {
elem.classList.toggle('active');
trigger.classList.toggle('active');
})
.flier {
pointer-events: none;
top: 0;
left: 0;
transform: translateX(-120%) translateY(-120%) rotateZ(0);
position: fixed;
z-index: 999999;
}
.flier.active {
animation: fly 50s linear infinite;
animation-delay: 1s;
}
.activate {
display: inline-block;
padding: 2em;
background: red;
color: white;
}
.activate.active {
display: inline-block;
padding: 2em;
background: green;
color: white;
}
#keyframes fly {
98.001%, 0% {
display: block;
transform: translateX(-200%) translateY(100vh) rotateZ(0deg)
}
15% {
transform: translateX(100vw) translateY(-100%) rotateZ(180deg)
}
15.001%, 18% {
transform: translateX(100vw) translateY(-30%) rotateZ(0deg)
}
40% {
transform: translateX(-200%) translateY(3vh) rotateZ(-180deg)
}
40.001%, 43% {
transform: translateX(-200%) translateY(-100%) rotateZ(-180deg)
}
65% {
transform: translateX(100vw) translateY(50vh) rotateZ(0deg)
}
65.001%, 68% {
transform: translateX(20vw) translateY(-200%) rotateZ(180deg)
}
95% {
transform: translateX(10vw) translateY(100vh) rotateZ(0deg)
}
}
<div class="flier">
<img src="https://via.placeholder.com/150" />
</div>
Go

Related

How to set duration/number of times to trigger a CSS animation - specifically for a flying image across screen

I found a css code for a flying image across the screen from this website:
https://support.cargo.site/Make-an-Image-Fly-Across-the-Screen. I will also paste the code here for quick reference.
Currently, the image flies non-stop. How to make it fly only based on the number of times that we can set?
Here's the code for HTML:
<div class="flier">{image 1}</div>
Here's the code for CSS:
.flier {
pointer-events: none;
}
.flier > * {
/* Adjust animation duration to change the element’s speed */
animation: fly 50s linear infinite;
pointer-events: none !important;
top: 0;
left: 0;
transform: translateX(-120%) translateY(-120%) rotateZ(0);
position: fixed;
animation-delay: 1s;
z-index: 999999;
}
/* Keyframe values control where the element will begin
and end its trajectory across the screen. Each rule
represents a path the element follows across the screen. */
#keyframes fly {
98.001%, 0% {
display: block;
transform: translateX(-200%) translateY(100vh) rotateZ(0deg)
}
15% {
transform: translateX(100vw) translateY(-100%) rotateZ(180deg)
}
15.001%, 18% {
transform: translateX(100vw) translateY(-30%) rotateZ(0deg)
}
40% {
transform: translateX(-200%) translateY(3vh) rotateZ(-180deg)
}
40.001%, 43% {
transform: translateX(-200%) translateY(-100%) rotateZ(-180deg)
}
65% {
transform: translateX(100vw) translateY(50vh) rotateZ(0deg)
}
65.001%, 68% {
transform: translateX(20vw) translateY(-200%) rotateZ(180deg)
}
95% {
transform: translateX(10vw) translateY(100vh) rotateZ(0deg)
}
}
Thanks in advance!
*Update: Issue solved! Just change the 'infinite' to a number.

How can you modify a cargo CSS animation to restrict movement within the screen/viewport?

I'm pretty new to CSS animations and I'm building a website on Cargo. I'm using this preset code that helps us make images fly across the screen. I have reduced the speed and made my own modifications to that code like this -
.flier {
pointer-events: none;
}
.flier > * {
/* Adjust animation duration to change the element’s speed */
animation: fly 200s linear infinite;
pointer-events: none !important;
top: 0;
left: 0;
transform: translateX(-120%) translateY(-120%) rotateZ(0);
position: fixed;
animation-delay: 0s;
z-index: -1;
/*z-index: 999999;*/
}
#keyframes fly {
98.001%, 0% {
display: block;
transform: translateX(-200%) translateY(100vh) rotateZ(0deg)
}
15% {
transform: translateX(100vw) translateY(-100%) rotateZ(180deg)
}
15.001%, 18% {
transform: translateX(100vw) translateY(-30%) rotateZ(0deg)
}
40% {
transform: translateX(-200%) translateY(3vh) rotateZ(-180deg)
}
40.001%, 43% {
transform: translateX(-200%) translateY(-100%) rotateZ(-180deg)
}
65% {
transform: translateX(100vw) translateY(50vh) rotateZ(0deg)
}
65.001%, 68% {
transform: translateX(20vw) translateY(-200%) rotateZ(180deg)
}
95% {
transform: translateX(10vw) translateY(100vh) rotateZ(0deg)
}
}
How do I modify the code further to restrict the image movement only within my viewport so the image doesn't disappear completely when it goes off the page?
I also would like the object to be at the center of the page when the page loads/animation starts.

How can I move an element upside down while moving forward?

.anim-cat-2 img {
animation: animcats 10s infinite;
}
#keyframes animcats {
0% {
transform: translate(100px, 100px)rotate(-15deg);
}
10% {
transform: translate(150px, -100px) rotate(15deg);
}
20% {
transform: rotate(-15deg) translate(200px, 100px);
}
30% {
transform: rotate(15deg)translate(250px, -100px);
}
40% {
transform: rotate(-15deg)translate(300px, 100px);
}
50% {
transform: rotate(15deg)translate(350px, -100px);
}
60% {
transform: rotate(-15deg)translate(400px, 100px);
}
70% {
transform: rotate(15deg)translate(450px, -100px);
}
80% {
transform: rotate(-15deg)translate(500px, 100px);
}
90% {
transform: rotate(15deg)translate(550px, -100px);
}
100% {
transform: rotate(-15deg)translate(600 px, 100px);
}
}
<div class="anim-cat-2">
<img src="https://66.media.tumblr.com/95927edf9e85ece73dac69ade623432c/tumblr_otrmgaTiin1vxe4v6o1_400.png" style="height: 130px;width: 180px;margin-top: 20px;">
</div>
i cant make it go smoothly forward in right tilt, its suppossed to make the right angle and move up and down moving forward. i already tried to change the degree, x n y axis but it still didnt work,please help me
Run code snippet.
Although it makes the right angle, move up and down, it did'nt meets the expectation at the end of the animation.
.anim-cat-2 img {
animation: animcats 8s infinite;
}
#keyframes animcats {
0% {
transform: rotate(0deg) translate(0px,0px);
}
8% {
transform: rotate(9deg);
}
10% {
transform: translate(100px,150px);
}
20% {
transform:rotate(-9deg) translate(100px,150px);
}
30% {
transform: translate(200px,0px);
}
40% {
transform: rotate(9deg) translate(200px,0px);
}
50% {
transform: translate(300px,150px);
}
60% {
transform: rotate(-9deg) translate(300px,150px);
}
70% {
transform: translate(400px,0px);
}
80% {
transform: rotate(9deg) translate(400px,0px);
}
90% {
transform: translate(500px,150px);
}
100% {
transform: rotate(-9deg) translate(500px,150px);
}
}
<div class="anim-cat-2">
<img src="https://66.media.tumblr.com/95927edf9e85ece73dac69ade623432c/tumblr_otrmgaTiin1vxe4v6o1_400.png" style="height: 130px;width: 180px;margin-top: 20px;">
</div>

CSS phone ringng animation

I want to have my font awesome icon "ring" each 1 seconds, by ring I mean having a css animation which makes the phone look like if it where ringing (maybe a brief rotation with transform origin center?), I'm a noob with css animations:
<div style="width:50px; height:50px; border-radius:50%; display:flex; align-items:center; justify-content:center; background-color:white;"><i class="LAYOUTnav7_links_button_icon fa fa-phone fs_bigger main"></i></div>
Any help?
You can use animation and keyframes to do this, here is an example:
.phone {
display:block;
width: 60px;
height: 60px;
font-size: 40px;
margin:50px auto 0;
color: #9e9e9e;
animation: ring 4s .7s ease-in-out infinite;
transform-origin: 50% 4px;
}
#keyframes ring {
0% { transform: rotate(0); }
5% { transform: rotate(30deg); }
10% { transform: rotate(-28deg); }
15% { transform: rotate(34deg); }
20% { transform: rotate(-32deg); }
25% { transform: rotate(30deg); }
30% { transform: rotate(-28deg); }
35% { transform: rotate(26deg); }
40% { transform: rotate(-24deg); }
45% { transform: rotate(22deg); }
50% { transform: rotate(-20deg); }
55% { transform: rotate(18deg); }
60% { transform: rotate(-16deg); }
65% { transform: rotate(14deg); }
70% { transform: rotate(-12deg); }
75% { transform: rotate(10deg); }
80% { transform: rotate(-8deg); }
85% { transform: rotate(6deg); }
90% { transform: rotate(-4deg); }
95% { transform: rotate(2deg); }
100% { transform: rotate(-1deg); }
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<div>
<span class="phone fa fa-phone"></span>
</div>

I added a CSS animation but it doesn't work and everything looks fine

So I tried to add a simple vibration animation to a link from my website but it simply doesn't work. Anyone see anything wrong with my code?
I took the animation code from animista.net and there they were working
Here is my code:
a {
text-decoration: none;
animation: vibrate 1s linear infinite both;
}
#keyframes vibrate {
0% {
transform: translate(0);
}
20% {
transform: translate(-2px, 2px);
}
40% {
transform: translate(-2px, -2px);
}
60% {
transform: translate(2px, 2px);
}
80% {
transform: translate(2px, -2px);
}
100% {
transform: translate(0);
}
}
Drop me a line and let’s do cool things together!
You can set position: absolute or change display value to block-level (because a is inline by default) for transform to work.
a {
text-decoration: none;
display: block; /* Or inline-block */
animation: vibrate 1s linear infinite both;
}
#keyframes vibrate {
0% { transform: translate(0); }
20% { transform: translate(-2px, 2px); }
40% { transform: translate(-2px, -2px); }
60% { transform: translate(2px, 2px); }
80% { transform: translate(2px, -2px); }
100% { transform: translate(0); }
}
Drop me a line and let’s do cool things together!
The CSS animation is not used to target anchor.
so please use div for easy animation effects
<!DOCTYPE html>
<html>
<head>
<style>
.div {
text-decoration: none;
position:relative;
animation:vibrate 1s linear infinite both;
}
#keyframes vibrate {
0% {
transform: translate(0,0);
}
20% {
transform: translate(-2px, 2px);
}
40% {
transform: translate(-2px, -2px);
}
60% {
transform: translate(2px, 2px);
}
80% {
transform: translate(2px, -2px);
}
100% {
transform: translate(0);
}
}
</style>
</head>
<body>
<div class="div">
Drop me a line and let’s do cool things together!
</div>
</body>
</html>