How to try to add sticky effect to your CSS

How to try to add sticky effect to your CSS

Written in front

I don’t know who first discovered that filter:blur and filter:contrast can produce such a wonderful chemical reaction, but it doesn’t matter. What’s important is that if you learn how to use this special effect, you can add cool effects to your web pages! Then please take a look at two small demos

demo

How to do it?

If you look closely, the elements on the web page seem to have viscosity. When the elements are close enough, a fusion effect will occur. When the elements are far away, there will be a sticky effect. How is this achieved?

It's very simple. You just need to add filter:blur to the child element and increase the contrast on its parent element.

They look like this (a simpler demo is shown below):

Code part:

 <div class="wrapper">
        <div class="container">
            <div class="box"></div>
        </div>
       </div>
 .wrapper{
            width: 100%;
            height: 100vh;
            position: absolute;
            background-color: #333;
            filter:contrast(50)
        }
        .container {
            position: absolute;
            top:50%;
            left:50%;
            width: 200px;
            height: 100px;
            background-color: #00eeff;
            filter: blur(10px) ;
        } 
        .box{
            width:25px;
            height:25px;
            background-color: #00eeff;
            border-radius: 50%;
            position: absolute;
            left:50%;
            transition: 1s;
            filter: blur(1px);
            animation: move 1s linear infinite;
         }
   @keyframes move {
       0%{
           transform: translateY(0);
       }
       100%{
           transform: translateY(-100px);
       }
   }

You can always copy the code and try it yourself!

principle:

When elements all have the blur attribute, the upper one is the parent without contrast (hereinafter referred to as Figure 1), and the lower one is the parent with contrast (hereinafter referred to as Figure 2). When the elements are merged, did you find that Figure 1 also has a fusion effect in it! It's just not clear, which is caused by blur. The contrast attribute can effectively combat blur and achieve the effect shown in Figure 2.

See the figure below

This is the end of this article about trying to add a sticky effect to your CSS. For more relevant CSS sticky content, please search 123WORDPRESS.COM’s previous articles or continue browsing the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  How to remove the blue box that appears when the image is used as a hyperlink

>>:  Method for comparing the size of varchar type numbers in MySQL database

Recommend

Example code for implementing 3D Rubik's Cube with CSS

Let's make a simple 3D Rubik's Cube today...

Jenkins Docker static agent node build process

A static node is fixed on a machine and is starte...

How to check whether a port is occupied in LINUX

I have never been able to figure out whether the ...

Complete steps for uninstalling MySQL database

The process of completely uninstalling the MySQL ...

JS realizes automatic playback of timeline

Recently, I have implemented such an effect: clic...

How to pop up a temporary QQ dialog box to chat online without adding friends

In fact, this is very simple. We add an a tag to ...

mysql batch delete large amounts of data

mysql batch delete large amounts of data Assume t...

Summary of @ usage in CSS (with examples and explanations)

An at-rule is a declaration that provides instruc...

The top fixed div can be set to a semi-transparent effect

Copy code The code is as follows: <!DOCTYPE ht...

mysql server is running with the --skip-grant-tables option

The MySQL server is running with the --skip-grant...

XHTML Getting Started Tutorial: Simple Web Page Creation

Create your first web page in one minute: Let'...

JavaScript to achieve fancy carousel effect

This article shares two methods of implementing t...