Home Web Front-end JS Tutorial javascript image zoom function implementation code_image special effects

javascript image zoom function implementation code_image special effects

May 16, 2016 pm 06:04 PM
Picture enlargement zoom out

Look at the JS source code:

Copy code The code is as follows:

// Zoom in and out control
var PhotoSize = {
zoom: 0, // Zoom rate
count: 0, // Number of zooms
cpu: 0, // Current zoom multiple value
elem: "", // Picture Node
photoWidth: 0, // Initial width record of picture
photoHeight: 0, // Initial height record of picture

init: function(){
this.elem = document.getElementById( "focusphoto");
this.photoWidth = this.elem.scrollWidth;
this.photoHeight = this.elem.scrollHeight;

this.zoom = 1.2; // Set basic parameters
this.count = 0;
this.cpu = 1;
},

action: function(x){
if(x === 0){
this .cpu = 1;
this.count = 0;
}else{
this.count = x; // Add record
this.cpu = Math.pow(this.zoom, this. count); // Any power operation
};
this.elem.style.width = this.photoWidth * this.cpu "px";
this.elem.style.height = this.photoHeight * this.cpu "px";
}
};
// Start the zoom effect and load it in onload mode to prevent the first click from not getting the width and height of the image
window.onload = function(){PhotoSize.init()};

It is recommended to use onload method to reference, which can accurately read the size of the initial image
Statement of this Website
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 Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

HTML, CSS and jQuery: Techniques for achieving special effects of zooming in and out of images HTML, CSS and jQuery: Techniques for achieving special effects of zooming in and out of images Oct 24, 2023 am 10:22 AM

HTML, CSS and jQuery: Techniques for achieving special effects of zooming in and out of images

Guide to resizing the search bar in Windows 10 Guide to resizing the search bar in Windows 10 Jan 04, 2024 pm 05:22 PM

Guide to resizing the search bar in Windows 10

How to implement mouse-over magnification effect on images with JavaScript? How to implement mouse-over magnification effect on images with JavaScript? Oct 20, 2023 am 09:16 AM

How to implement mouse-over magnification effect on images with JavaScript?

How to use Vue to implement image scrolling and zoom animation? How to use Vue to implement image scrolling and zoom animation? Aug 18, 2023 am 08:13 AM

How to use Vue to implement image scrolling and zoom animation?

Use uniapp to implement image zooming and zooming functions Use uniapp to implement image zooming and zooming functions Nov 21, 2023 am 11:58 AM

Use uniapp to implement image zooming and zooming functions

How to use Layui to achieve a slideshow effect of zooming in and out of images How to use Layui to achieve a slideshow effect of zooming in and out of images Oct 27, 2023 am 10:51 AM

How to use Layui to achieve a slideshow effect of zooming in and out of images

How to reduce wps to half screen size How to reduce wps to half screen size Mar 20, 2024 pm 09:40 PM

How to reduce wps to half screen size

How Vue solves the flickering problem of gesture-enlarged pictures on mobile terminals How Vue solves the flickering problem of gesture-enlarged pictures on mobile terminals Jun 30, 2023 pm 11:21 PM

How Vue solves the flickering problem of gesture-enlarged pictures on mobile terminals

See all articles