Use css3 to scale the browser

Source: Internet
Author: User

Author: Jiang Yujie (hfahe)

Copyright statement: original works. You are welcome to reprint them. During reprinting, you must mark the original source, author information, and this statement in hyperlink form.

 

Css3 provides powerful transform attributes for animation effects. Next I will introduce how to use css3 to scale the browser.

HTML page

First, we need to write a simple page to test the code for page scaling.

There are two buttons on the page. One is to zoom in, the other is to zoom in, and the other is to zoom out.

JavaScript code

You can use transform: scale to set the scale of the body to scale the entire page. The JS Code is as follows:

VaR size = 1.0; </P> <p> function zoomout () {<br/> size = size + 0.1; </P> <p> set (); <br/>}</P> <p> function zoomin () {<br/> size = size-0.1; </P> <p> set (); <br/>}</P> <p> function set () {<br/> document.body.style.css text = document.body.style.css text + ';-WebKit-transform: scale ('+ size +'); '; <br/>} 

Shows the scaling effect:

This effect is similar to that of chrome, but it is somewhat different from our expectation: The current scaling is based on the center of the DIV, and we want the scaling to be based on the origin in the upper left corner, how should we solve this problem?

Css3 also has an attribute called transform-origin, which is used to set the start point of transform. The default value is the midpoint of the element. We need to set it to the upper left corner to meet the requirements. The code for modifying style settings is as follows:

Document.body.style.css text = document.body.style.css text + ';-WebKit-transform: Scale (' + size + ');-WebKit-transform-origin: 0 0 ;'; 

The new results are as follows:

Combined with browsers

Chrome plug-ins are actually simple, and the preceding script is directly inserted in background.html for calling.

To implement the native functions of the browser, run the above JS script directly in the executejavascript method of cefframe.

Using the above method, we can use js to implement many functions in the browser, such as slice rotation and page font setting.

 

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.