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 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1248
24
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 implementing image zoom-in and zoom-out effects, specific code examples are required. With the development of the Internet, the design of web pages pays more and more attention to user experience. Among them, pictures, as one of the important elements of web design, can often bring users an intuitive and rich visual experience. The special effect of zooming in and out of images can enhance users' perception and interaction with web content, so it is widely used in web design. This article will introduce how to use HTML, CSS and jQuery to achieve special effects of zooming in and out of images, and provide

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

Users feel that the search box that comes with win10 is too big in the taskbar and is very annoying. They ask how to reduce the search box size in win10. Generally, you just need to turn it into an icon to reduce the size. Let’s take a look at how to reduce the size of the search box in win10 in detail. Tutorial. How to reduce the size of the search box in Windows 10: 1. Right-click the taskbar and multiple functions will pop up. 2. Find the search function item in it. 3. Turn on the search function, and we choose to display the search icon (W) to zoom out. 4. After setting it up, it will become a reduced version of the icon, as shown below.

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? Today's web design pays more and more attention to user experience, and many web pages add some special effects to pictures. Among them, the picture mouse-over magnification effect is a common special effect, which can automatically enlarge the picture when the user hovers the mouse, increasing the interaction between the user and the picture. This article will introduce how to use JavaScript to achieve this effect and give specific code examples. Idea analysis: To achieve the mouse-over magnification effect of images, we can use JavaS

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? Vue.js is a popular JavaScript framework that provides a rich set of features and components that enable developers to easily build interactive and dynamic web applications. One of the common application scenarios is to implement image scrolling and zooming animations. In this article, we will learn how to use Vue.js to implement such functionality and provide corresponding code examples. First, we need to prepare a data list containing multiple images. We can change the UR of the image

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

Nowadays, there are more and more computer software, and new software may replace the old software at any time. So why is WPS software always used by people and has not withdrawn from the stage with the trend of the times? This is mainly Thanks to the powerful editing functions of wps software, which cannot be replaced by other software, it is more suitable for people's needs. So today we will learn a function of wps software: how to reduce the window to half screen size in wps. Although it is not used frequently, But everyone should also understand this function. 1. Opening a wps document window can be reduced through the view function. Find the view on the toolbar above and click on it. 2. After clicking on the view, click on the display ratio in the toolbar below 3. After clicking on the display ratio,

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 the slideshow effect of enlarging and reducing images. The slideshow effect is one of the common image display methods on websites. It attracts the user's attention through the enlargement and reduction of images. In this article, we will introduce how to use the Layui framework to achieve the zoom-in and zoom-out slideshow effect of images, and provide specific code examples. Layui is a simple, easy-to-use front-end UI framework that provides rich components and powerful functions. The Carousel component can be used to achieve slide effects. First, we need to introduce

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

Using uniapp to implement image zoom-in and zoom-out functions In mobile application development, image display and operation is a common requirement. This article will introduce how to use uniapp to realize the image zoom function. uniapp is a cross-platform application framework based on Vue.js, which can generate both Android and iOS applications through a set of codes. In uniapp, we can use the uni-image component to display and operate images. First, create a page in the project to display images.

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 to solve the flickering problem of mobile-side gesture amplification pictures in Vue development. Mobile-side gesture zooming pictures is a common user interaction method. However, in Vue development, due to the influence of the rendering mechanism, flickering problems may occur when gestures enlarge pictures. This article will introduce a way to solve this problem. First, we need to understand what is causing this problem. On the mobile terminal, we usually use the transform:scale() property of CSS to achieve the effect of gesture enlarging the image. This can maintain the quality of the image.

See all articles