Astuce #11: Créer une loupe pour zoomer une image en Javascript

2 Mar 2021 · 10 min
10:17

In this French tutorial, the presenter demonstrates how to build an image magnifier (loupe) that follows the mouse cursor using HTML, CSS, and JavaScript. The video walks through creating a div element (identified as "loop") that serves as the magnifying glass, styling the page and the lens with a background image (starfish.jpg), setting dimensions, border radius, shadow, and hiding the default cursor. Media queries are suggested for responsive sizing. The CSS also defines the lens’s background size and applies a brightness filter for clarity. In JavaScript, a zoom factor (e.g., 2) is defined, and an onMouseMove event on the body updates the lens’s left/top positions based on the mouse coordinates. The script calculates the background-size (original width multiplied by zoom) and background-position using the lens’s offset values multiplied by the zoom factor, with a centering correction (e.g., -150 px) to align the zoomed view. Additional CSS tweaks such as overflow:hidden prevent scrollbars when the lens approaches the edges. The tutorial concludes with a functional magnifier that shows detailed image sections, useful for e‑commerce product pages.

Chapters

More from Yamossoun

8:56
youtube.com

Compteur synchrone - Logique séquentielle

2w ago
11:58
youtube.com

Compteur asynchrone et diviseur de fréquence - Logique séquentielle

3w ago
11:37
youtube.com

Les registres (parallèle et à décalage) - Logique séquentielle

1mo ago
6:14
youtube.com

Bascule T (Toggle) - Logique séquentielle

1mo ago
12:05
youtube.com

Bascule JK - Logique séquentielle

1mo ago
9:17
youtube.com

Bascule D flip-flop active sur front montant - Logique séquentielle

1mo ago
10:08
youtube.com

Bascule D Latch - Logique séquentielle

1mo ago
8:13
youtube.com

Bascule RS - Logique séquentielle

1mo ago
5:04
youtube.com

Logique séquentielle - Introduction

2mo ago
1:15
youtube.com

Le codeur - Logique combinatoire #codeur #logique #circuit #booleanlogic

2mo ago
1:56
youtube.com

Algorithme de calcule de la racine carrée par dichotomie #dichotomy #squareroot #algorithm

3mo ago
See all content