gpt4 book ai didi

javascript - 如何让div独立

转载 作者:行者123 更新时间:2023-11-27 23:40:49 24 4
gpt4 key购买 nike

function createDiv() {
var yellowButton = document.getElementById("yellowColor");
var newNote = document.createElement('div');


document.getElementById('theText1').innerHTML = document.getElementById("textOfNote").value;
newNote.innerHTML = document.getElementById('theText1').innerHTML;
document.getElementById("canvas").appendChild(newNote);
newNote.style.display = "inline-block";
newNote.className = "segments";

newNote.classList.add('draggable');
$('.draggable').draggable({
containment: "canvas"
});

newNote.classList.add('resizable');
$('.resizable').resizable();

}


function genPDF() {
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};

doc.fromHTML($('#canvas').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');


}
<script src="app.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>

<!-- <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> -->
<link rel="stylesheet" href="https://resources/demos/style.css">

<style>

.draggable {
cursor: move;
}

.segments {
display: block;
border : 1px solid black;
font-family: "Montserrat";
font-weight: 200;
word-wrap: break-word;
white-space: pre-wrap;
}

#yellowNoteStyle {
/*
width: 400px;
height: 400px;
margin: 10px;
*/
display: block;
font-family: "Montserrat";
font-weight: 200;
word-wrap: break-word;
white-space: pre-wrap;

}
</style>

<link rel="stylesheet" type="text/css" href="app.css">

<head>
<title> Minimal Cheatsheet Builder </title>
</head>
<left>
<h1> cheat it - minimal cheatsheet builder</h1>
</left>

<style>
.indent-1 {float: left;}
.indent-1 section {width: 50%; float: left;}
</style>

<section class="indent-1">
<!-- Section 1 -->
<section id="addnote">
<div>
<left>
<form action="mainpage.php" method="post">
<h3> Insert onto cheatsheet. </h3>
<textarea id="textOfNote"></textarea>
<br/>
<br/>
<table style="display:none">
<tr>
<td> <input type="radio" name="color" value="yellow" id="yellowColor" /> </td>
</tr>

<tr>
<td>
<div id="yellowNoteStyle"> </div>
</td>
</tr>

</table>
<br/>
</form>
</left>
</div>

<div id="create">
<button onClick="createDiv()">Create Segment</button>
</div>


<div id="trash" style="width:50mm; height:50mm">
<h3>trashcan</h3>
</div>
</section>

<script>
$( function() {
$( "#trash" ).droppable({
drop: function( event, ui ) {
ui.draggable.remove();
}
});
} );
</script>

<!-- Section 2 -->
<section>
<div id="canvas" style="width: 297mm; height: 210mm"></div>


<button id="gen" onClick="genPDF()">generate PDF</button>

</section>
</section>

<br>


<div id="yellowNote" style="display: none;">
<div id="yellowNoteStyle" ></div>
<p><span id='theText1'></span></p>
</div>
</div>

我制作了一个简单的 Web 应用程序,它允许您创建动态 div

您可以在此处查看应用程序的外观:调整大小之前 https://imgur.com/JOgCPKh调整大小后 https://imgur.com/VERc4PV

当按下创建段按钮时,在旧的 div 旁边创建一个新的 div

通过这种方式添加的动态 div 可以通过 jQuery 使用 jQuery ui 的 draggable and resizable 方法进行拖动和调整大小。

draggable 功能运行良好,但不能调整大小。看起来 div 是相关的,当您尝试调整它的大小时,它取决于其他动态 div 的大小。

function createDiv() {
var yellowButton = document.getElementById("yellowColor");
var newNote = document.createElement('div');


document.getElementById('theText1').innerHTML = document.getElementById("textOfNote").value;
newNote.innerHTML = document.getElementById('theText1').innerHTML;
document.getElementById("canvas").appendChild(newNote);
newNote.style.display = "inline-block";
newNote.className = "segments";

newNote.classList.add('draggable');
$('.draggable').draggable({
containment: "canvas"
});

newNote.classList.add('resizable');
$('.resizable').resizable();

}

最佳答案

你为什么评论 jquery ui css?。删除评论,它将起作用。

 <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

function createDiv() {
var yellowButton = document.getElementById("yellowColor");
var newNote = document.createElement('div');


document.getElementById('theText1').innerHTML = document.getElementById("textOfNote").value;
newNote.innerHTML = document.getElementById('theText1').innerHTML;
document.getElementById("canvas").appendChild(newNote);
newNote.style.display = "inline-block";
newNote.className = "segments";

newNote.classList.add('draggable');
$('.draggable').draggable({
containment: "canvas"
});

newNote.classList.add('resizable');
$('.resizable').resizable();

}


function genPDF() {
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};

doc.fromHTML($('#canvas').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');


}
<script src="app.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://resources/demos/style.css">

<style>

.draggable {
cursor: move;
}

.segments {
display: block;
border : 1px solid black;
font-family: "Montserrat";
font-weight: 200;
word-wrap: break-word;
white-space: pre-wrap;
}

#yellowNoteStyle {
/*
width: 400px;
height: 400px;
margin: 10px;
*/
display: block;
font-family: "Montserrat";
font-weight: 200;
word-wrap: break-word;
white-space: pre-wrap;

}
</style>

<link rel="stylesheet" type="text/css" href="app.css">

<head>
<title> Minimal Cheatsheet Builder </title>
</head>
<left>
<h1> cheat it - minimal cheatsheet builder</h1>
</left>

<style>
.indent-1 {float: left;}
.indent-1 section {width: 50%; float: left;}
</style>

<section class="indent-1">
<!-- Section 1 -->
<section id="addnote">
<div>
<left>
<form action="mainpage.php" method="post">
<h3> Insert onto cheatsheet. </h3>
<textarea id="textOfNote"></textarea>
<br/>
<br/>
<table style="display:none">
<tr>
<td> <input type="radio" name="color" value="yellow" id="yellowColor" /> </td>
</tr>

<tr>
<td>
<div id="yellowNoteStyle"> </div>
</td>
</tr>

</table>
<br/>
</form>
</left>
</div>

<div id="create">
<button onClick="createDiv()">Create Segment</button>
</div>


<div id="trash" style="width:50mm; height:50mm">
<h3>trashcan</h3>
</div>
</section>

<script>
$( function() {
$( "#trash" ).droppable({
drop: function( event, ui ) {
ui.draggable.remove();
}
});
} );
</script>

<!-- Section 2 -->
<section>
<div id="canvas" style="width: 297mm; height: 210mm"></div>


<button id="gen" onClick="genPDF()">generate PDF</button>

</section>
</section>

<br>


<div id="yellowNote" style="display: none;">
<div id="yellowNoteStyle" ></div>
<p><span id='theText1'></span></p>
</div>
</div>

关于javascript - 如何让div独立,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57054651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com