简体   繁体   English

水平滚动时jQuery的可拖动错误

[英]jquery draggable bug when scrolling horizontally

thing is that i got this helped from someone here to drag a div but if you wanted to scroll down/up it wouldn't be possible, with this code, that won't happen: 事情是,我从这里的某人那里得到了帮助来拖动div,但是如果您想向下/向上滚动,使用此代码将是不可能的:

$(function() {
    $("#divname").draggable({
        start: function(event) {
            var content = $("#panel_content");

            // if we're scrolling, don't start and cancel drag
            if (event.originalEvent.pageX-content.offset().left > content.innerWidth())
            {
                $(this).trigger("mouseup");
                return false;
            }
        }
    });
});

Now, i could try to understand how this work, seems pretty logic, well thought. 现在,我可以尝试了解它是如何工作的,看起来很合理,经过深思熟虑。 I should now try to get the offset.top and validate it against the content.innerHeight(), right? 我现在应该尝试获取offset.top并针对content.innerHeight()进行验证,对吗? like this: 像这样:

event.originalEvent.pageY-content.offset().top > content.innerHeight()

Thing is, i've done a console.log to see these values constantly, and the innerHeight() is always the same (1242) doesn't matter how much i resize it. 事情是,我做了console.log来不断查看这些值,而innerHeight()始终是相同的(1242)不管我调整它的大小是多少。 Why is this happening? 为什么会这样呢? Should i be using another function to get the current Height of the div container? 我应该使用另一个函数来获取div容器的当前高度吗?

Thanks. 谢谢。

Okey solved this by using: Okey通过使用以下方法解决了这个问题:

event.originalEvent.pageY-content.offset().top > parent_content.innerHeight()

So the entire if-block according to my needs is: 所以根据我的需要,整个if块是:

$(function() {
    $("#sendmessage-panel-overlay").draggable({
        start: function(event) {
            var content = $("#panel_content");
            var parent_container = $("#sendmessage-panel-overlay");

            // if we're scrolling, don't start and cancel drag
            if (event.originalEvent.pageX-content.offset().left > content.innerWidth() ||
                    event.originalEvent.pageY-content.offset().top > (parent_container.innerHeight() - 34))
            {                   
                $(this).trigger("mouseup");
                return false;
            }
        }
    }).resizable();
}); 

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

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