简体   繁体   English

CSS缩放与Javascript缩放之战

[英]CSS zoom vs. Javascript zoom battle

Looking at this example fiddle (I'm using Chrome 33) 看这个小提琴示例(我使用的是Chrome 33)

the CSS and Javascript set zoom on the same object are working in unison, and not like normal styles should be by overriding.. and in a selective manner. CSS和Javascript集在同一对象上的缩放效果是一致的,并且不应该像普通样式那样通过重写和选择方式来进行缩放。

CSS 的CSS

#text { zoom: 0.8}

HTML 的HTML

<div>
    <div id='text'> text </div>
    <div id='other'> text fixed zoom 1</div>
</div>

^ an element with css zoom 0.8 looks at size 0.8. ^ css zoom 0.8的元素的大小为0.8。 great. 大。

var texty = document.getElementById('text');
texty.style.zoom = 1;

^ an element with css zoom 0.8 and a javascript (thus inline) zoom of 1 looks at size 1. great. ^如果元素的CSS缩放为0.8,而javascript(因此是嵌入式)缩放为1,则其尺寸为1。

This I expect, the inline style set by javascript should have precedence. 我希望这是由javascript设置的内联样式优先。

texty.style.zoom = 0.8;

^ BUT an element with css zoom 0.8 and a javascript zoom of 0.8 looks size 1 as well. ^但是具有CSS缩放0.8和JavaScript缩放0.8的元素看起来也为1。 (0.8/0.8). (0.8 / 0.8)。 Why now is it working together? 为什么现在一起工作?

The fiddle linked toggles the javascript set zoom value from 0.8 to 1, but no visual difference is found demonstrating the above issue. 链接的小提琴将javascript设置的缩放值从0.8切换为1,但没有发现视觉差异,这说明了上述问题。 I'd like to know why this is, and how to I work around it. 我想知道这是为什么,以及如何解决它。

The purpose of this is so that a series of rendered html cards enter the page at a default 0.8, and as they are programmatically selected they "zoom" up to 1, then as passed they are "zoomed" back to 0.8 but this return breaks. 这样做的目的是使一系列呈现的html卡以默认的0.8进入页面,并且通过编程选择它们将它们“缩放”到1,然后通过传递将它们“缩放”到0.8,但是返回返回。 It feels a waste to constantly scan the li's for new cards added to the list, hence I want a default zoom: 0.8 set via css. 不断扫描li的列表中是否有新卡,这很浪费,因此我想要一个默认的缩放比例:通过CSS设置为0.8。

I checked in newest chrome it is not working. 我检查了最新的Chrome浏览器是否正常运行。 I suspicious it is a bug. 我怀疑这是一个错误。 But you can work around it by set it to a slightly different value. 但是您可以通过将其设置为稍有不同的值来解决它。 For example in your case you could set it to 0.79 and it will work. 例如,您可以将其设置为0.79,它将起作用。

There is no zoom property in CSS standards, up to CSS3. 在CSS标准(不包括CSS3)中没有zoom属性。

It is originally a proprietary CSS standards by IE, but later adopted by other browsers. 它最初是IE专有的CSS标准,但后来被其他浏览器采用。 It is theoretically working in all major browsers (Firefox has its own syntax, though), but it's proven not working well in Chrome 33, by OP. 从理论上讲,它可以在所有主流浏览器上运行(尽管Firefox具有自己的语法),但是OP证明它不能在Chrome 33中正常运行。 Another proof that it is NOT recommended to be used in production sites. 不建议在生产现场使用的另一种证明。

If you want to scale the contents, you can use CSS transforms . 如果要缩放内容,可以使用CSS转换

ps If you change the text to an image, it works sometimes in Chrome. ps如果将文本更改为图像,则有时可以在Chrome中使用。

It is suggested that you can use the followings for images : 建议您对图像使用以下内容:

#test img {
  height: 100%;
  width: 100%; /* change from 100% to 80% for zoom: 0.8; effect */
}

For texts , you can just change the font-size (and for readability, you may want to change the line-height too). 对于text ,您可以只更改font-size (为了便于阅读,您可能还需要更改line-height )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM