简体   繁体   English

Mozilla / chrome / jquery可拖动图像不在鼠标位置

[英]Mozilla/chrome/JQuery Draggable image not on mouse position

I am busy with a webpage where an image is draggable and droppable in another element. 我正忙于一个网页,该网页中的图片可以在其他元素中拖放。

On chrome, everything works perfect and the image is draggable across the whole screen 在chrome上,一切工作正常,图像可在整个屏幕上拖动

On Firefox, the image X axis is perfectly underneath mouse, but the Y axis isnt. 在Firefox上,图像X轴恰好位于鼠标下方,但是Y轴不是。
It somehow stops at an "invisible" border. 它以某种方式在“看不见”的边界处停止。 The top-style wont go higher then -31. 最高样式不会升至-31。 and thus will not be able to be dropped across the whole screen. 因此无法将其拖放到整个屏幕上。 Only in the top part of the screen (about ~50px height) 仅在屏幕顶部(约50像素高)

I use the Jquery methods 我使用Jquery方法

$(".class").draggable({
    helper: "clone", 
    revert: false,
    containment: "body",
    scroll: false
});

and

    $('#element').droppable({
        accept: ".class",

And to identify the position of the mouse i use this code: 为了确定鼠标的位置,我使用以下代码:

        var offsetTop = $XXXX.offset().top;
        var offsetLeft = $XXXX.offset().left;

I have also tried to use .offset().bottom but this was the exact same result. 我也尝试过使用.offset()。bottom,但这是完全相同的结果。 I have also tried to use 我也尝试使用

$(window).load(function ($) {

instead of: 代替:

$(document).ready(function ($) {

But this made the whole draggable element not draggable anymore. 但这使整个可拖动元素不再可拖动。 (both on chrome and firefox) (同时适用于chrome和Firefox)

I have also used the method: .offsetTop instead of offset().top but this didnt change anything. 我还使用了以下方法:.offsetTop而不是offset()。top,但这没有任何改变。 Same problem as before. 与以前一样的问题。

The solution was: the method draggable had this option: containment: "Body". 解决方案是:可拖动方法具有以下选项:包含:“正文”。 This was wrong and should've been: false. 这是错误的,应该是:false。

So final code: 所以最后的代码:

$(".class").draggable({
    helper: "clone", // use a clone for the visual effect
    revert: false,
    containment: false,
    scroll: false
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM