【问题标题】:ContentEditable image resize in chrome, what is the best solution?chrome中的ContentEditable图像调整大小,最好的解决方案是什么?
【发布时间】:2013-10-10 13:12:02
【问题描述】:

我正在尝试在 Chrome 上使用 contentEditable 集成图像大小调整。我知道 webkit 关于此功能的正常操作存在问题,所以我想知道如果用户使用 Google Chrome(jQuery 插件?Javascript 方法?),集成图像调整大小的最佳替代方法是什么。

<div contenteditable>
  <img src="http://www.thebrandbite.com/wp-content/media/2015/07/apple-7.jpg" width=200 />
</div>

这是 Firefox 开箱即用的工作方式:

【问题讨论】:

    标签: javascript jquery html google-chrome contenteditable


    【解决方案1】:

    您的选择是:

    1. 使用库。它们肯定存在:例如,YUI 有一个image resize module。我从未使用过它,但该演示适用于我尝试过的所有桌面浏览器。

    2. 自己编写:为调整大小手柄添加一些可拖动的定位元素。我以前做过,如果你知道自己在做什么,这并不难。

    【讨论】:

    • 这是怎么引起注意的?使用 YUI - 以前从未使用过。如果你知道自己在做什么,这并不难
    • @JonathanC:我显然认为这个问题是要求一种通用方法而不是一些工作代码。我承认这不是我最好的答案。
    【解决方案2】:

    @Tim-Down 答案可能是更好的解决方案。 但我想说的是,如果你不想用它做任何进一步的事情,你可以只用 CSS 来调整图像的大小:

    http://codepen.io/anon/pen/JEEKqO

        resize: both;
        background-size: contain;
        background-repeat: no-repeat;
        background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-after.jpg);
    

    body {
      background-color: #1D1F1F;
    }
    
    section { 
      display: table;
      margin: 0 auto;
    }
    
    div {
      resize: both;
      background-color: white;
      overflow: scroll;
      background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-after.jpg');
      background-size: cover;
      background-repeat: no-repeat;
    } 
    <section>
      <button>both</button>
      <button>horizontal</button>
      <button>vertical</button>
      <button>none</button>
    <div class="resize"></div>
    </section>

    【讨论】:

    • 谢谢,但这应该在一个可编辑的 (contenteditable) div 中,因此图像应该保持可选择状态(剪切/粘贴、复制/粘贴图像应该可以工作,等等)。因此,具有 1px 边框 + 小调整大小手柄的 UI 可能更适合此目的。感谢您的尝试!
    猜你喜欢
    • 2021-06-06
    • 2012-05-11
    • 1970-01-01
    • 2018-08-06
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    相关资源
    最近更新 更多