CSS to achieve the image hovering mouse folding effect

CSS to achieve the image hovering mouse folding effect

CSS to achieve the image hovering mouse folding effect

1. Implementation points

  • The fold is accomplished by multiple block-level elements;
  • The picture is presented as a background picture;
  • Set the same background image for each block-level element, and use background-position to control the display area (similar to a sprite image);
  • The folding effect is achieved through the ransform attribute;
  • The size of the entire wrapped div is the original size of the image. If the size is changed, you need to adjust the background-size and other properties to adjust the background image size.

2. Effect display

Picture folding effect display

3. Source code

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>hover-folder</title>
  <style>
    html,
    body,
    ul,
    li {
      margin: 0;
      padding: 0
    }

    ul {
      list-style: none;
      display: block;
    }

    body {
      width: 100%;
      height: 100vh;
    }

    .container {
      width: 100%;
      height: 100%;
      /* background-color: aqua; */
      display: flex;
      justify-content: center;
      align-items: center;
      transform: scale(0.5);
    }

    .wrap {
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .5);
      width: 1280px;
      height: 854px;
      font-size: 0;
      line-height: 0;
      position: relative;

    }

    .image {
      cursor: pointer;
    }

    .abs-wrap {
      height: 100%;
      width: 100%;
      /* top: 0;
      left: 0; */
      /* position: absolute; */
      z-index: 10;

    }

    .abs-wrap:hover>.abs:nth-child(2) {
      transform: matrix(0.8, -0.2, 0, 1, -1, 0);
    }

    .abs-wrap:hover>.abs:nth-child(3) {
      transform: matrix(0.8, 0.2, 0, 1, -53, -50);
    }

    .abs-wrap:hover>.abs:nth-child(4) {
      transform: matrix(0.8, -0.2, 0, 1, -105, 0);
    }

    .abs-wrap:hover>.abs:nth-child(5) {
      transform: matrix(0.8, 0.2, 0, 1, -157, -50);
    }

    .abs {
      transform-style: preserve-3d;
      transform-origin: left center;
      transition: .4s ease-in-out;
      width: 20%;
      height: 100%;
      /* background-color: rgba(0, 0, 0, .5); */
      display: inline-block;
      background-size: 100%;
      background: url('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600577868615&di=d2979a54604ecb409e3329527d0220fa&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D29311073%2C358824429%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D1280%26h%3D854');
    }

    .abs:nth-child(1) {
      background-position: 0% 0%;
    }

    .abs:nth-child(2) {
      background-position: 25% 0%;
    }

    .abs:nth-child(3) {
      background-position: 50% 0%;
    }

    .abs:nth-child(4) {
      background-position: 75% 0%;
    }

    .abs:nth-child(5) {
      background-position: 100% 0%;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="wrap">
      <ul class="abs-wrap">
        <li class="abs"></li>
        <li class="abs"></li>
        <li class="abs"></li>
        <li class="abs"></li>
        <li class="abs"></li>

      </ul>

    </div>

  </div>

</body>

</html>

Summarize

This is the end of this article about how to use CSS to achieve the folding effect when the mouse is hovering over an image. For more relevant CSS content about folding an image when the mouse is hovering over an image, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  How to use the jquery editor plugin tinyMCE

>>:  Summary of HTML horizontal and vertical centering issues

Recommend

The whole process of installing and configuring Harbor1.7 on CentOS7.5

1. Download the required packages wget -P /usr/lo...

JS implements dragging the progress bar to change the transparency of elements

What I want to share today is to use native JS to...

How to prevent website content from being included in search engines

Usually the goal of building a website is to have...

Implementation of CSS circular hollowing (coupon background image)

This article mainly introduces CSS circular hollo...

Front-end JavaScript Promise

Table of contents 1. What is Promise 2. Basic usa...

How to debug loader plugin in webpack project

Recently, when I was learning how to use webpack,...

Example analysis of the use of GROUP_CONCAT in MySQL

This article uses an example to describe how to u...

What is flex and a detailed tutorial on flex layout syntax

Flex Layout Flex is the abbreviation of Flexible ...

Html to achieve dynamic display of color blocks report effect (example code)

Use HTML color blocks to dynamically display data...

Detailed explanation of system input and output management in Linux

Management of input and output in the system 1. U...

Understand CSS3 Grid layout in 10 minutes

Basic Introduction In the previous article, we in...

How to use a game controller in CocosCreator

Table of contents 1. Scene layout 2. Add a handle...

UDP connection object principle analysis and usage examples

I wrote a simple UDP server and client example be...

Analyzing the troublesome Aborted warning in MySQL through case studies

This article mainly introduces the relevant conte...

JavaScript Advanced Closures Explained

Table of contents 1. The concept of closure Addit...