search
HomeDaily ProgrammingCSS KnowledgeHow to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)

This article mainly introduces you to the specific method to achieve the magnification effect when the mouse slides over the picture.

When we browse major e-commerce websites, the most common dynamic effect of pictures should be the enlargement effect when the mouse moves into the picture or hovers over the picture. The main purpose of achieving such dynamic effects is to highlight product content and improve user experience.

For code novices, this effect is certainly very attractive, but if you want to achieve it through html/css code, you may not know where to start.

In fact, the code implementation is very simple. Below we will use a simple example to introduce to you the method of enlarging the image after the mouse passes.

The html/css code example for the magnification effect of moving the mouse into the picture is as follows:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>html/Css3实现图片缩放</title>
    <style type="text/css">
        #div1{
            width: 500px;
            margin: 150px auto;
        }
        #div1 img{
            transition: all 0.5s;
            border-radius:5px;
            border: #eee solid 2px;
        }
        #div1 img:hover{
            transform: scale(1.5);
        }
    </style>
</head>
<body style="background: #000">
<div id="div1">
    <img  src="/static/imghwm/default1.png"  data-src="123123.png"  class="lazy"   / alt="How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)" >
</div>
</body>
</html>

First visit the front desk, and the picture effect is as shown below:

How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)

Then when we hover the mouse over the picture, the effect is as follows:

How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)

It is obvious from the picture that the picture has been enlarged.


You can copy this code directly and test it locally. Some of the main css/css3 properties used here are:

border-radius: to div Add a rounded border to the element.

:hover The selector is used to select the element on which the mouse pointer is floating.

transform : Applies a 2D or 3D transform to an element. This property allows us to rotate, scale, move or tilt the element. where, the value scale(x,y) Define the 2D scaling transformation. (This example sets the image zoom to 1.5 times)

transition: An abbreviated attribute used to set four transition attributes. (This example sets the transition time when the image is enlarged to 0.5 seconds to avoid the effect being too abrupt)

This article is about using html/css/css3 to achieve the effect of enlarging the image when the mouse passes over it. Very simple and easy to understand, I hope it will be helpful to friends in need!

If you want to learn more about HTML/css, you can follow the PHP Chinese website

HTML video tutorial and CSS video tutorial, CSS3 video tutorial , welcome everyone to refer to and study!

The above is the detailed content of How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor