在运行时禁用 CTRL/滚轮缩放效果
如何使用 css 或 javascript 在某些元素上禁用 ctrl/wheel 缩放效果。 我创建了一个菜单栏,当应用缩放效果时,该菜单栏会变形。 我想仅对某些元素禁用它。
How do you disable the ctrl/wheel zoom effect with css or javascript on certain elements. I create a menu bar that gets distorted when the zoom effect is applied. I would like to disable it for just certain elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更好的主意:设计您的布局,使其足够强大以处理此类更改。 即使您修复了字体大小(您一开始就不应该这样做),您也无法禁用它们,因此您不妨优雅地响应缩放。
事实是,如果浏览器对所有元素进行同等缩放,那么您的页面的外观和工作方式应该与以前完全相同(除了,你知道,更大),除非您在设计中的某个地方采用了一些懒惰的快捷方式。
Better idea: design your layout so that it's robust enough to handle changes like this. You can't disable them, even if you fix the font size (which you should never do in the first place), so you might as well respond to zooming gracefully.
The fact is, if all elements are scaled equally by the browser, your page should look and work exactly the same way as it did before (except, y'know, bigger) unless you took some lazy shortcuts in your design somewhere.
IE和Firefox的解决方案:
solution for IE and Firefox:
你不能; 这是浏览器功能,而不是文档功能。
话虽如此,如果您使用 CSS 的 style="font-size: 9px;",您可以覆盖文本大小。 浏览器缩放仍然有效,并且浏览器字体大小更改将产生一些重新格式化效果。
You can't; this is a browser feature, not a document feature.
Having said that, if you use CSS's style="font-size: 9px;", you can override text size. Browser zoom will still work, and browser font size changes will have some reformatting effects.
这是我的问题:
我一直用 em 进行设计,它们的效果非常神奇。 但通过全页缩放,我的背景也会放大。如果我有一个重复图案作为主背景,我不希望它变得像素化。
它们确实帮助我们避免了一些工作,比如实现 Doug Bowman 的 CSS 滑动门,但现在我不得不忍受模糊的选项卡。
我还有另一个关于全页缩放的问题,至少在当今的浏览器中是这样实现的:
我是将浏览器设置为 12pt 字体而不是 16pt 的“那些”人之一。 每隔一段时间,我就会遇到一个(当然是固定宽度的)网站,它将文本大小调整为很小的尺寸(我猜他们在尝试制作它时使用了 0.9em 或其他东西,而不是 14px)更小)。 我通常只会放大一两级,一切都会好起来的。 但是,使用全页缩放时,图像缩放效果很差,而且我有一个水平滚动条。
第一个问题的解决方案是允许背景图像标签中的某种处理指令禁止对该元素进行全页缩放。 或者可能是文档头部的某些内容。 如果浏览器真的想公平一点,他们还可以为用户提供一个可以设置的选项,该选项可以覆盖无缩放指令,这样他们就可以根据需要进行缩放。
第二个问题的解决方案是,全页缩放时先以 16px/em 的速率将所有 px 转换为 em,然后然后缩小到您的文本大小,而不是将 px 转换为em 使用您的文字大小作为基础。 然后向后滚动到 16 像素将使图像达到预期的完美尺寸。
Here's my problem:
I've always designed with ems, and they work magically. But with full-page zoom, my backgrounds are also zoomed in. If I have a repeating pattern as the main background, I don't want that to become pixelized.
They do help us avoid some work, like implementing Doug Bowman's Sliding Doors of CSS, but now I have to live with blurry tabs.
I also have another problem with full-page zoom, at least as it's implemented in today's browsers:
I'm one of 'those' people who set my browser to 12pt font instead of 16pt. Every once in a while, I'd come across a (fixed-width, of course) site that resizes the text to a tiny size (I'm guessing they used 0.9em or something, instead of 14px, while trying to make it smaller). I'd usually just zoom in a notch or two, and all would be well. With full-page zoom, though, the images scale badly and I have a horizontal scrollbar.
The solution to the first problem would be to allow some sort of processing instruction in the background-image tag to disallow full-page zoom on that element. Or maybe something in the document's head. If browsers really want to be fair about it, they could also give the users an option they could set that over-rides the no-zoom instruction, so they could zoom anyway if they so choose.
The solution to the second problem would be for full-page zoom to convert all the px into em at a rate of 16px/em first, and then zoom down to your text size, instead of converting px to em using your text size as a base. Then scrolling back up to 16px would make the images perfectly-sized, as intended.