gpt4 book ai didi

ios - 在安装的 phonegap 中使用拖放

转载 作者:行者123 更新时间:2023-11-29 12:41:29 24 4
gpt4 key购买 nike

作为我的 IOS 应用程序的一部分,我正在使用简单的 HTML 代码处理拖放功能。这段代码在浏览器中完美运行,但是当我将它复制到我的 xcode 文件中时,图像不会拖动。

<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
#div1 {width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;}
</style>
<script>
function allowDrop(ev)
{
ev.preventDefault();
}

function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}

function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>

<p>Drag the image into the rectangle:</p>

<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br>
<img id="drag1" src="images/face.png" draggable="true" ondragstart="drag(event)" width="336" height="69">

</body>
</html>

最佳答案

阅读 Apple 的 webview capabilities 文档指出您必须设置一个 CSS 属性才能使其工作。

来自文档:

Making an Element Draggable

WebKit provides automatic support to let users drag common items, such as images, links
and selected text. You can extend this support to include specific elements on an HTML
page. For example, you could mark a particular div or span tag as draggable.

To mark an arbitrary element as draggable, add the -webkit-user-drag attribute
(previously -khtml-user-drag) to the style definition of the element. Because it is a
cascading style sheet (CSS) attribute, you can include it as part of a style definition
or as an inline style attribute on the element tag. The values for this attribute are
listed in Table 1.

所以标准的 draggables 将开箱即用,但其他元素如 divspan 需要 -webkit-user-drag 属性待追加。

例子:

#drag1 { -webkit-user-drag: element; }

来源:https://developer.apple.com/library/mac/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/DragAndDrop.html

关于ios - 在安装的 phonegap 中使用拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24761742/

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