Several ways to implement image rotation in Web pages

Source: Internet
Author: User

There are three common implementations of image rotation in Web pages:

First, IE filter

IE's graphics rotation filter, which rotates the element by specifying the rotation value of the basicimage filter, rotates in a clockwise direction, and the center point of the rotation is the upper-left corner of the element. Rotation can have 4 rotation values: 0, 1, 2, and 3, respectively, to rotate the element 0 degrees, 90 degrees, 180 degrees, 270 degrees.

Browser support: ie5.5+

CSS code:

. rotate{Filter:progid:DXImageTransform.Microsoft.BasicImage (rotation=3);}

  

JS Code:

element.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";  

Second, CSS3 transform

The Transform property of CSS3 allows us to rotate, scale, and move elements. You can rotate an element by passing a rotate (degree) value to it, positive values are rotated clockwise, negative values are rotated counterclockwise, and the center of the rotation is the center of the element.

Browser support: Firefox 4+, Oprea + +, Safari 3.1+, Chrome 8+, IE + +

CSS code:

.rotate{    -ms-transform:rotate(90deg); /* IE 9 */    -moz-transform:rotate(90deg); /* Firefox */    -webkit-transform:rotate(90deg); /* Safari and Chrome */    -o-transform:rotate(90deg); /* Opera */}  

JS Code:

element.style.webkitTransform="rotate(-90deg)"element.style.MozTransform="rotate(-90deg)"element.style.msTransform="rotate(-90deg)"element.style.OTransform="rotate(-90deg)"element.style.transform="rotate(-90deg)";

Third, HTML5 canvas rotate

Using the Context.rotate (angle) method of the canvas 2d drawing context object, the rotation of the picture is achieved by specifying the radian rotation axis that needs to be rotated, positive values are rotated clockwise, negative values are rotated counterclockwise, and the center point of the rotation is the top left corner of the canvas. The equation for angle conversion radians is: radians = angle * math.pi/180.

Browser support:Chrome 1.0+,Firefox 1.5+,Opera 9.0+,Safari 1.3+, IE + +

JS Code:

context = canvas.getContext("2d")context.rotate(90 * Math.PI / 180);context.drawImage(img, 0, -img.height);

Several ways to implement image rotation in Web pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.