gpt4 book ai didi

javascript - 无法手动拉伸(stretch)可拖动的 div

转载 作者:行者123 更新时间:2023-12-02 22:55:02 26 4
gpt4 key购买 nike

我创建了一个可拖动的div:

function dragElement(elmnt) {
var pos1 = 0,
pos2 = 0,
pos3 = 0,
pos4 = 0;
if (document.getElementById(elmnt.id + "Header")) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id + "Header").onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}

function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}

function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}

function closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
}

dragElement(document.getElementById("infoVehicule"));
<div id="infoVehicule">
<div id="infoVehiculeHeader"></div>
<p id="infoVehiculeContent"></p>
<p id="infoVehiculeTrajets"></p>
</div>

在运行时我无法拉伸(stretch)它以手动放大其宽度。那么如何手动拉伸(stretch)这个div来扩大它的宽度呢?

最佳答案

您可以使用jqueryui resizing插件手动放大div的宽度

为了更好地理解附加 jsfiddle

关于javascript - 无法手动拉伸(stretch)可拖动的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58028431/

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