scribd如何实现缩放?

发布于 2024-12-26 12:49:48 字数 413 浏览 1 评论 0原文

Scribd 的缩放功能非常令人印象深刻。当您单击 + 和 - 按钮时,所有页面内容(包括图像和文本)都会按比例缩放。

例如,请在 http://www.scribd.com/html5 上尝试。

他们是如何做到这一点的?它似乎不像控制浏览器缩放那么简单(尽管控制浏览器缩放本身并不简单,如果根本不可能!)

一个相关的问题是他们如何实现“全屏模式”。这个问题之前被问过,但那是两年前的事了,当时他们仍在使用Flash。

Scribd's zooming functionality is very impressive. All the page content including images and text are zoomed proportionally when you click on their + and - buttons.

For example, try it on http://www.scribd.com/html5.

How do they do this? It doesn't seem to be as simple as controlling the browser zoom (although controlling browser zoom itself is not simple if not possible at all!)

A related question would be how they implement their 'full screen mode'. This question was asked before but that was two years ago when they were still using Flash.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界等同你 2025-01-02 12:49:48

我建议这可能是 canvas 元素,但查看其来源,情况似乎并非如此。

相反,它看起来像“放大”功能只影响页面上的 img 标签,所以我想说它们可能只是动态修改 width 和 <这些标签的 code>height 属性。这不是一种非常复杂的方法,并且当然不依赖于 HTML5 中引入的任何内容。

编辑:

Chrome 的开发者工具非常棒。如果您观察缩​​放之间的 DOM,就很容易查明效果是如何实现的。这是页面默认状态下标记的样子:

<div class="outer_page only_ie6_border" id="outer_page_1" 
     style="width: 516.8000000000015px; height: 400px; ">
      <div class="newpage" id="page1" 
           style="width: 902px; height: 697px; 
                 -webkit-transform: scale(0.5729490022172966); 
                 -webkit-transform-origin-x: 0%; 
                 -webkit-transform-origin-y: 0%; ">
      ...
</div>
</div>

...以及缩小一次之后:

 <div class="outer_page only_ie6_border" id="outer_page_1" 
     style="width: 646.0000000000018px; height: 500px; ">
      <div class="newpage" id="page1" 
           style="width: 902px; height: 697px; 
                 -webkit-transform: scale(0.7161862527716206); 
                 -webkit-transform-origin-x: 0%; 
                 -webkit-transform-origin-y: 0%; ">
      ...
</div>
</div>

...以及再次缩小之后:

<div class="outer_page only_ie6_border" id="outer_page_1" 
     style="width: 807.5000000000023px; height: 624px; ">
      <div class="newpage" id="page1" 
           style="width: 902px; height: 697px; 
                 -webkit-transform: scale(0.8952328159645258); 
                 -webkit-transform-origin-x: 0%; 
                 -webkit-transform-origin-y: 0%; ">
      ...
</div>
</div>

因此看来他们通过做两件事来实现缩放效果:

  1. 增加 容器 div 的宽度高度
  2. 使用 webkit-transform CSS 属性来放大内容或根据需要向下。

I'd suggest that it might be a simple transformation of a canvas element, but looking at their source this does not appear to be the case.

Instead, it looks like the "Zoom In" function only affects the img tags on the page, so I'd say that probably they are just dynamically modifying the width and height attributes for those tags. It's not a very sophisticated approach, and certainly doesn't rely on anything introduced in HTML5.

Edit:

Chrome's developer tools are excellent. If you observe the DOM between zooms, it's easy to pinpoint how the effect is being implemented. Here's what the markup looks like in the page's default state:

<div class="outer_page only_ie6_border" id="outer_page_1" 
     style="width: 516.8000000000015px; height: 400px; ">
      <div class="newpage" id="page1" 
           style="width: 902px; height: 697px; 
                 -webkit-transform: scale(0.5729490022172966); 
                 -webkit-transform-origin-x: 0%; 
                 -webkit-transform-origin-y: 0%; ">
      ...
</div>
</div>

...and after zooming out once:

 <div class="outer_page only_ie6_border" id="outer_page_1" 
     style="width: 646.0000000000018px; height: 500px; ">
      <div class="newpage" id="page1" 
           style="width: 902px; height: 697px; 
                 -webkit-transform: scale(0.7161862527716206); 
                 -webkit-transform-origin-x: 0%; 
                 -webkit-transform-origin-y: 0%; ">
      ...
</div>
</div>

...and after zooming out again:

<div class="outer_page only_ie6_border" id="outer_page_1" 
     style="width: 807.5000000000023px; height: 624px; ">
      <div class="newpage" id="page1" 
           style="width: 902px; height: 697px; 
                 -webkit-transform: scale(0.8952328159645258); 
                 -webkit-transform-origin-x: 0%; 
                 -webkit-transform-origin-y: 0%; ">
      ...
</div>
</div>

So it appears that they have implemented their zoom effect by doing two things:

  1. Increasing the width and height of the container div.
  2. Using the webkit-transform CSS property to scale the contents up or down as needed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文