• Latest
How To Do Deletion Animations With CSS

How To Do Deletion Animations With CSS

December 15, 2021
Samsung Galaxy XCover6 Pro official with 5G connectivity and removable back

Samsung Galaxy XCover6 Pro official with 5G connectivity and removable back

June 29, 2022
Performance Tuning Strategies for SQL Server Index

Performance Tuning Strategies for SQL Server Index

June 29, 2022
Developers compare Meta to Apple, accuse it of hypocrisy

Developers compare Meta to Apple, accuse it of hypocrisy

June 29, 2022
Exclusive First Look At Atari 50: The Anniversary Celebration

Exclusive First Look At Atari 50: The Anniversary Celebration

June 29, 2022
Skull & Bones Appears to Be Arriving in November

Skull & Bones Appears to Be Arriving in November

June 29, 2022
Return To Monkey Island Might Be The Last Game In The Series

Return To Monkey Island Might Be The Last Game In The Series

June 29, 2022
Delete TikTok from app stores, says FCC commissioner

Delete TikTok from app stores, says FCC commissioner

June 29, 2022
Rhythm Arcade Game ‘Loud’ Takes You From The Basement To The Big Stage This July

Rhythm Arcade Game ‘Loud’ Takes You From The Basement To The Big Stage This July

June 29, 2022
Overwatch 2 drops gameplay trailer showcasing Junker Queen

Overwatch 2 beta now live

June 29, 2022
Using blurs and motion to be creative in photography

Using blurs and motion to be creative in photography

June 29, 2022
Portal Modders Have Already Got Half-Life 2 Running On Switch

Portal Modders Have Already Got Half-Life 2 Running On Switch

June 29, 2022
Here’s A Brand New Look At The ‘Legend Of Mana’ Anime Releasing This Year

Here’s A Brand New Look At The ‘Legend Of Mana’ Anime Releasing This Year

June 29, 2022
Advertise with us
Wednesday, June 29, 2022
Bookmarks
  • Login
  • Register
GetUpdated
  • Home
  • Game Updates
    • Mobile Gaming
    • Playstation News
    • Xbox News
    • Switch News
    • MMORPG
    • Game News
    • IGN
    • Retro Gaming
  • Tech News
    • Apple Updates
    • Jailbreak News
    • Mobile News
  • Software Development
  • Photography
  • Contact
    • Advertise With Us
    • About
No Result
View All Result
GetUpdated
No Result
View All Result
GetUpdated
No Result
View All Result
ADVERTISEMENT

How To Do Deletion Animations With CSS

December 15, 2021
in Software Development
Reading Time:4 mins read
0 0
0
Share on FacebookShare on WhatsAppShare on Twitter


In this quick tutorial, we’re going to be looking at a bunch of different ‘delete’ styles to use on your next project. So let’s take a look at some cool ways to delete things in your next project. Below are a set of delete animations that all work on similar principles. Let’s take a look at them and then we’ll jump into how they work. 

To start the animation, simply click the cross button on each card in the Codepen below.

How To Make UI Animated Deletion Effects

So although all the animations above are based on CSS principles, we need a little bit of Javascript to kick start them. The key Javascript function we need is an event for whenever the user clicks the cross button. First off, let’s make our card in HTML. Notice that we give the delete button an attribute called data-delete. This is how we track the type of animation to run.

<div class="item">
    <div class="image"></div>
    <div class="delete" data-delete="zoom"><i class="far fa-times"></i></div>
    <div class="text">
        <h2>Zoom Delete</h2>
        <p>Click the cross above to delete this item..</p>
    </div>
    <div class="animation-assets"></div>
</div> 

Next, let’s make our Javascript function to give animation to our cards. Although this looks a little bit more complicated, all this function does is add the text from data-delete in our HTML to the class of the .item div. If the animation is the shredder, we have to do a little bit more too:

  • First, we add 10 or so new divs to the .animation-assets div. We clip each of these so they look like shredded pieces of paper.
  • We then delay the animation a little for each, to give variety to each slice – and we alternate between two animations in our CSS – so we give different slices different animation names.
document.querySelectorAll('.delete').forEach(function(item) {
    item.addEventListener('click', function(e) {
        // First we get the 
        let newClass = this.getAttribute('data-delete');
        let getParent = parent(this, '.item', 1);
        if(newClass === 'shredder') {
            getParent.classList.add('shredding');
            // Shredder animation
            // Slices
            let shredAmount = 10;
            let width = document.querySelector('.item.shred').getBoundingClientRect().width / shredAmount;
            let animationName="spinALittle";
            let animationDelay = 0;
            for(let x = 0; x <= shredAmount; ++x) {
                animationDelay += 1;
                if(x % 2 === 0) {
                    animationName="spinALittleAlt";
                } else {
                    animationName="spinALittle";
                }
                if(x % 3 === 0) {
                    animationDelay = 0;
                }
                let newEl = document.createElement('div');
                newEl.classList.add('item-wrap');
                newEl.innerHTML = `<div class="item">${getParent.innerHTML}</div>`;
                newEl.querySelector('.animation-assets').innerHTML = '';
                let clip = `clip-path: inset(0px ${(shredAmount - x - 1) * width}px 0 ${(x * width)}px); animation-delay: 0.${animationDelay}s; transform-origin: ${x*width}px 125px; animation-name: ${animationName};`
                newEl.children[0].setAttribute('style', clip);
                getParent.querySelector('.animation-assets').append(newEl);
            }
        } else {
        getParent.classList.add(newClass);
        }
    });
}); 

CSS for Delete Animations

Next up, let’s look at our CSS. To create the animations, we use keyframes. First up, we add animations to each of our .item divs, based on the type of animation we want to show.

.item.zoom {
  animation: zoom forwards 0.7s ease-out 1;
}

.item.shredding {
   animation: reduceWidth forwards 1.7s ease-out 1; 
}

.item.fall {
    animation: fallAway forwards 1s ease-out 1;
}
.item.analogue {
    animation: analogue forwards 1s ease-out 1;
}
.animation-assets > .item-wrap > .item {
    animation: spinALittle 1.4s ease-out 1 forwards;
    perspective: 1000px;
    position: absolute;
    top: 0;
    left: 0;
}
.item-wrap {
    animation: dropShadow 0.1s ease-out forwards 1;
}

Then we make our animations. These do just a few things:

  • First, they do the main animation, which is usually some kind of transform
  • Then they reduce the padding, width, and margin to zero. This means items are removed smoothly from the card order.
  • Finally, we usually reduce the opacity to 0 so the items are no longer visible.

An example of the animation we use for the shredder is shown below:

@keyframes fallAway {
  0% {
    transform: rotateZ(0deg);
    top: 0;
    opacity: 1;
  }
  25% {
    transform: rotateZ(-15deg);
  }
  100% {
    top: 300px;
    transform: rotateZ(-5deg);
    opacity: 0;
  }
}

If you want to view the full code, you can do so via the codepen linked here. These delete animation styles were pretty fun to do – and there’s lots more you could do with them. If you come up with any cool ones, let me know in the comments below or on Twitter!





Source link

ShareSendTweet
Previous Post

01. Introduction | YouTube Success Script, Shoot & Edit with MKBHD

Next Post

Galaxy S21 Expert Review Highlights I Samsung

Related Posts

Performance Tuning Strategies for SQL Server Index

June 29, 2022
0
0
Performance Tuning Strategies for SQL Server Index
Software Development

An optimized approach to indexing is important if you are keen to keep the performance of an SQL Server instance...

Read more

Reactive Kafka With Streaming in Spring Boot

June 29, 2022
0
0
Reactive Kafka With Streaming in Spring Boot
Software Development

The AngularAndSpring project uses Kafka for the distributed sign-in of new users and the distributed token revocation for logged-out users....

Read more
Next Post
Galaxy S21  Expert Review Highlights I Samsung

Galaxy S21 Expert Review Highlights I Samsung

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2021 GetUpdated – MW.

  • About
  • Advertise
  • Privacy & Policy
  • Terms & Conditions
  • Contact

No Result
View All Result
  • Home
  • Game Updates
    • Mobile Gaming
    • Playstation News
    • Xbox News
    • Switch News
    • MMORPG
    • Game News
    • IGN
    • Retro Gaming
  • Tech News
    • Apple Updates
    • Jailbreak News
    • Mobile News
  • Software Development
  • Photography
  • Contact
    • Advertise With Us
    • About

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?