【问题标题】:How to make a div draggable and contenteditable="true"?如何使 div 可拖动和 contenteditable="true"?
【发布时间】:2015-10-28 19:14:49
【问题描述】:

我一遍又一遍地尝试,但我似乎可以让文本可编辑且可拖动,因为当我应用 .draggable() 时,contenteditable="true" 变为 "false"。

Javascript

$(".note").keyup(function() {
    $(this).css('height' , '100%');
});

HTML

<div class="note" contenteditable="true">
    <span id='close' onclick='this.parentNode.parentNode.removeChild(this.parentNode)'>
        <img src="images/close.png" height="30" width="30" align="right" style="vertical-align: top; float: right"/>
    </span>
</div>

CSS

.note {
    width: 280px;
    height: 130px;
    padding-top: 20px;
    margin-top: 60px;
    margin-left: 25px;
    padding: 2;
    word-break: break-word;
    font-family: Note;
    font-size: 20px;
    background-image: url("images/stickynote.png");
    background-repeat: no-repeat;
    background-size: cover;
    z-index: 1;
}

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    你可以这样做,这样如果你双击它就可以编辑,但单击它会拖动它。

    $(".note").draggable()
      .click(function() {
        $(this).draggable( {disabled: false});
    
    }).dblclick(function() {
        $(this).draggable({ disabled: true });
    });
    

    将此添加到关闭按钮&lt;img&gt; 代码会将其保留在容器的右上角:

    position: relative;
      top: -20px;
    

    【讨论】:

    • 这可行,但是现在在输入文本时关闭按钮会向下移动。有没有办法解决这个问题还是正常的。
    • 对按钮也进行了修复。
    • 我试过了,但是当我删除文本时,关闭按钮太高了。有没有办法让文字绕过关闭按钮
    • 嗯,就这样做而言,您最好的选择可能是让您的内容可编辑 div 在右侧有一个填充并覆盖您的关闭 div,有点像 example。这只会缩短您的文本框并在右侧增加空间,因此文本不能位于关闭按钮后面。
    猜你喜欢
    • 2016-05-07
    • 2020-01-27
    • 1970-01-01
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    相关资源
    最近更新 更多