簡體   English   中英

如何使div可拖動和contenteditable =“ true”?

[英]How to make a div draggable and contenteditable=“true”?

我已經嘗試了一遍又一遍,但是我似乎可以使文本變得可編輯和可拖動,因為當我應用.draggable()時,contenteditable =“ true”變為“ false”。

Java腳本

$(".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;
}

您可以這樣做,因此,如果雙擊它將是可編輯的,但是單擊將拖動它。

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

}).dblclick(function() {
    $(this).draggable({ disabled: true });
});

將其添加到關閉按鈕<img>代碼會將其保留在容器的右上方:

position: relative;
  top: -20px;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM