JavaScript/HTML/CSS: Zooming

2020-03-31 05:30发布

Let's say I've got a page with a div, and a button. When you click the button, the div should be zoomed in on. In other words, if that div was 100px, when you zoom, it should then become, say, 200px. And all the children of this div should also be doubled in size.

What's the best way to do this?

My understanding is that there's a CSS zoom, but only in IE--it's not part of any CSS standard.

2条回答
等我变得足够好
2楼-- · 2020-03-31 06:12

You might want to look into the jQuery plugin Zoomooz: http://janne.aukia.com/zoomooz/

查看更多
放我归山
3楼-- · 2020-03-31 06:20

You should use CSS3's transform: scale().

See: http://jsfiddle.net/Favaw/ - (I used jQuery for convenience, but it's not a requirement)

.zoomedIn2x {
    -moz-transform: scale(2);
    -webkit-transform: scale(2);
    -o-transform: scale(2);
    -ms-transform: scale(2);
    transform: scale(2);

    -moz-transform-origin: 0 0;
    -webkit-transform-origin: 0 0;
    -o-transform-origin: 0 0;
    -ms-transform-origin: 0 0;
    transform-origin: 0 0;
}

If you need to support older versions of IE than 9, then generate .zoomedIn2x using this tool:

If you want to do this more dynamically (such as other levels of zoom), then instead use cssSandpaper.

查看更多
登录 后发表回答