html5 draggable隐藏原始元素 [英] html5 draggable hide original element

查看:1000
本文介绍了html5 draggable隐藏原始元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当开始使用HTML5 draggable属性拖动元素时,原始元素仍然可见,所以我最终得到两个元素而不是一个。

When starting to drag an element using HTML5 draggable attribute, original element is still visible, so I end up having two elements visible instead of one.

我怎么能do只有被拖动的元素可见(原始元素应该暂时隐藏)。

How can I do to have only the element being dragged visible (the original one should be momentarily hidden).

<script>
  function startDrag() {
    // hide initial element
  }

  function endDrag() {
    // reset initial element
  }
</script>

<div class="draggable" draggable="true"
  ondragstart="startDrag(event)"
  ondragend="endDrag(event)"
></div>

这是一个显示问题的方法 https://jsfiddle.net/gjc5p4qp/

Here's a jsfiddle to show the problem https://jsfiddle.net/gjc5p4qp/

推荐答案

你可能会成功这是一个hacky解决方案。原生可拖动性不允许CSS样式,如:不透明度:0; 可见性:隐藏 display:none

You may succeed this a hacky solution. The native draggability doesn't allow CSS styles like: opacity:0;, visibility:hidden or display:none.

但你可以使用: transform:translateX(-9999px)

我已更新您的 JSFiddle 与解决方案。

I've updated your JSFiddle with the solution.

这篇关于html5 draggable隐藏原始元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆