Hey I don't like asking such open questions but, I'm quite lost with this one. I'm trying to figure out how to do drag and drop specifically for touch devices. All the online tutorials I've seen for drag and drop have some weird if(IE) statements that make it hard to read and then they don't even work on touch devices. It's driving me crazy because this is so easy to do in actionScript and I'm still learning JS.
Much to my dismay I couldn't even get addEventListener to work:
<html>
<head>
<title>Drag and Drop test</title>
<style type="text/css">
#box{
top:200px;
width:100px;
height:100px;
background:red;
position:relative;
}
#box2{
top:200px;
width:100px;
height:100px;
background:black;
position:relative;
}
</style>
</head>
<body>
<div id="box">something something something</div>
<div id="box2"></div>
<script type="text/javascript">
function doSomething() {
myImage.style.width = '200px';
开发者_如何学Python}
var myImage = document.getElementById('box');
myImage.addEventListener('click', doSomething, false);
</script>
</body>
</html>
I actually pulled this code for addEventListener from the answer of another question but it doesn't seem to work. I'm running safari if that is important. Thanks
You definitely need to use a JavaScript framework. The complexity of DD in a desktop web app is hard enough, let alone on a mobile device. Take a look at YUI3's Drag and Drop. It has some kind of mobile support:
Native gesture support was added to DD in 3.2.0. This support is transparent and the implementor should not have to do anything to use this functionality. When dd is used, loader will check the device to see if it contains support for Gesture Events, if the device supports these events the dd-gestures module will automatically be loaded as well as it's dependencies. At this point, DD will operate as usual but it will utilize the native gesture events instead of mouse based events.
精彩评论