Home Web Front-end JS Tutorial Three ways to achieve image rotation with js_javascript skills

Three ways to achieve image rotation with js_javascript skills

May 16, 2016 pm 04:53 PM
Picture rotation

1 使用jQueryRotate.js实现

示例代码:

复制代码 代码如下:


















测试结果:chrome下效果正常,旋转后img对象仍为img对象;ie8下效果正常,但旋转后img对象变为下面对象,由于对象变化,若旋转后仍按原来方法获取img对象,则会报js错误。欲获取image对象,可根据class获取。如果图像旋转后,不进行其它操作,则可用此方法。若进行其它操作,如放大、缩小图像,则此方法实现较复杂。
复制代码 代码如下:







2 使用Microsoft提供的Matrix对象

示例代码:
复制代码 代码如下:

















测试结果:chrome下效果正常,但旋转后img对象变为canvas对象;ie8下效果正常,旋转后img对象仍为img对象。Matrix()参数较多,使用时需较多计算。

3 使用Microsoft提供的BasicImage对象

示例代码:
复制代码 代码如下:














Test Result: Rotation cannot be done under chrome; the effect is normal under ie8, and the img object is still an img object after rotation. BasicImage() has only one parameter.

Looking at the codes of these three methods, you will find that it is essentially a solution: using the canvas object under chrome, and using VML or Matrix() or BasicImage() under ie8. I recently renovated a component: it involves rotating and enlarging images. Since jQueryRotate.js will generate a new object under IE8, special processing is required when selecting an image before enlarging it. Finally, it was decided to handle chrome and ie8 separately. jQueryRotate was used to implement it under chrome, and BasicImage() was used under ie8 to ensure the simplicity and readability of the code.
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

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)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months 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)

How to use JavaScript to achieve image rotation effect? How to use JavaScript to achieve image rotation effect? Oct 20, 2023 pm 07:09 PM

How to use JavaScript to achieve image rotation effect? In web development, we often encounter scenarios where image rotation effects need to be achieved, such as displaying 360° rotation images of products, achieving image carousel effects, etc. JavaScript is a powerful scripting language that can easily achieve this image rotation effect. The following will introduce a method to achieve image rotation effects based on JavaScript and provide specific code examples. First, we create a simple HTML structure

Use uniapp to implement image rotation function Use uniapp to implement image rotation function Nov 21, 2023 am 11:58 AM

Using uniapp to implement image rotation function In mobile application development, we often encounter scenarios where images need to be rotated. For example, the angle needs to be adjusted after taking a photo, or an effect similar to the rotation of a camera after taking a photo is achieved. This article will introduce how to use the uniapp framework to implement the image rotation function and provide specific code examples. uniapp is a cross-platform development framework based on Vue.js, which can simultaneously develop and publish applications for iOS, Android, H5 and other platforms. Implemented in uniapp

Implement image rotation effect in WeChat applet Implement image rotation effect in WeChat applet Nov 21, 2023 am 08:26 AM

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to

How to realize image rotation using PHP and GD library How to realize image rotation using PHP and GD library Jul 12, 2023 am 11:52 AM

How to implement image rotation using PHP and GD libraries Image rotation is a common image processing requirement. By rotating images, you can achieve some special effects or meet user needs. In PHP, you can use the GD library to implement the image rotation function. This article will introduce how to use PHP and the GD library to implement image rotation, with code examples. First, make sure your PHP environment has the GD library extension installed. Enter php-m on the command line to check if there is a gd module. If not, you need to install it first. Here is a simple

How to solve the problem of mobile image rotation in Vue development How to solve the problem of mobile image rotation in Vue development Jun 29, 2023 pm 09:22 PM

With the rapid development of the mobile Internet, more and more websites and applications are beginning to use Vue.js for mobile development. However, during mobile development, we often encounter the problem of image rotation. Image rotation means that when a user takes a photo on a mobile device, due to the change in device orientation, the angle of the photo displayed on the page is inconsistent with the actual shooting angle. To solve the problem of image rotation, you first need to understand the reason why the image is rotated. When a user takes a photo on a mobile device, the device automatically adds some metadata to the photo.

How to implement image rotation and flipping in Golang How to implement image rotation and flipping in Golang Aug 27, 2023 pm 01:03 PM

Golang's method of rotating and flipping images. In image processing, it is often necessary to rotate and flip images. This article will introduce how to use Golang to rotate and flip images, and provide corresponding code examples. First, we need to import the image and image/draw packages: import("image" "image/draw") Next, we define a function

Methods to optimize image rotation and scaling performance in Java development Methods to optimize image rotation and scaling performance in Java development Jun 30, 2023 pm 04:34 PM

With the development of the Internet, image processing has become more and more common. In Java development, it is often necessary to deal with the rotation and scaling of images. How to optimize the performance of these operations has become a concern for developers. This article will discuss how to optimize the performance of image rotation and scaling in Java development. First, let's understand the principles of image rotation and scaling. Image rotation refers to rotating the image by a certain angle counterclockwise or clockwise according to the rotation center. Image scaling refers to reducing or enlarging the image by changing its size. Open in Java

Best practices for image rotation using PHP and GD library Best practices for image rotation using PHP and GD library Jul 12, 2023 am 09:53 AM

Overview of best practices for image rotation using PHP and GD libraries: Image rotation is one of the common requirements in web development. By rotating images, you can change the direction of the image or adjust the angle of the image. In PHP, the image rotation function can be implemented through the GD library. This article will introduce how to use PHP and the GD library to implement image rotation, and share some best practices and code examples. 1. Install the GD library. Before starting, we need to ensure that the GD library has been installed on the server. If it is not installed, you can follow the following steps

See all articles