拖放在Firefox中不起作用

drag and drop not working in firefox(拖放在Firefox中不起作用)
本文介绍了拖放在Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 J​​Query 和 html5 中实现了拖放功能,它在 chrome 中运行良好,但在 Firefox 中运行良好,下面是我的代码,我在其中警告丢弃图像的 id,它在 Firefox 中显示为未定义,下面是我的代码,请帮助.jsfiddle:http://jsfiddle.net/rajutikale/2R6p8/

I have implemented drag and drop functionality in JQuery and html5 , its working great in chrome but stuck in Firefox following is my code where i am alerting id of dropped image which appears as undefined in Firefox following is my code , please help . jsfiddle: http://jsfiddle.net/rajutikale/2R6p8/

查看:

<!-- dragable image --> 
<a href="#?w=976" rel="popup1" id="<?=$album['album_id'].'-'.$data->content_id?>" class="poplight album_photos"><img  id="<?=$album['album_id'].'-'.$data->content_id?>" draggable="true" ondragstart="drag(event)" ondragover="allowDrop(event)" alt="" src="<?=$imagePath?>"></a>

<input type="hidden" id="<?='wall'.$data->content_id?>" value="<?=$data->wall_id?>" />
<input type="hidden" id="<?='type'.$data->content_id?>" value="<?=$data->content_type?>" />
<input type="hidden" id="<?='user'.$data->content_id?>" value="<?=$_SESSION['user_type']?>" />

<!-- dropable area -->
<div class="" style="z-index: 1; position:fixed; right:124px; top:60px" id="div1" ondrop="drop(event);;" ondragover="allowDrop(event);"> <a href="#"><img id="dropzon_image"src="<?php echo IMAGE_PATH_HTTP?>babbler_btn.jpg" alt="" border="0" style="cursor: pointer; cursor: hand; "/></a>
    <div id="overlay" style="display:none;z-index: 2;  position:fixed; right:0px; top:32px; cursor: pointer;border-color: blueviolet;">
        <img id="drop_image" src="<?php echo IMAGE_PATH_HTTP?>drop_image.jpg" alt="" border="1" style="cursor: pointer; cursor: hand; " />
    </div>
</div>

JS:

function allowDrop(ev) {
    ev.preventDefault();
}

function drag(ev) {
    ev.dataTransfer.setData("Text", ev.target.id);
    $("#div1").find("#overlay").slideDown();
    setTimeout(function () {
        $("#overlay").hide();
    }, 4000);
}

function drop(ev) {
    var id = ev.dataTransfer.getData("Text"); /*implimented solution*/
    alert(id);
    ev.preventDefault();
    var action = 'download';
    var wall_id = '62';
    var stat = 'Album';
    var cnt = '0';
    var user_type = 'R';
    var status = do_download(action, wall_id, stat, cnt, user_type);
    $("#overlay").hide();
    // ev.target.appendChild(document.getElementById(data));
}

推荐答案

根据https://developer.mozilla.org/en-US/docs/Web/Events/dragstart 将数据设置为 null(如示例的 html 部分或事件函数中):

According to https://developer.mozilla.org/en-US/docs/Web/Events/dragstart set data to null (like in html part of the example, or in the event function) with:

event.dataTransfer.setData('text/plain', null);

Chromium 不需要那个.

Chromium doesn't need of that.

这篇关于拖放在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)