load() 之后的 JQuery 拖放 - 拖放工作正常但拖放损坏

发布于 2024-11-30 00:13:11 字数 1511 浏览 0 评论 0原文

我有一个简单的 jquery 设置,涉及一些带有图像的 div 和一些需要拖到图像上的文本。如果我单独运行该页面,一切都很好。不幸的是,按照我设置的方式,这是一个 html 页面,由 jQuery load() 加载到父页面上的 div 中,当我这样做时,尽管拖动有效,但放置却无效。有什么想法吗?谢谢。

$(document).ready(function () {
    $('.draggable').live('mouseover', function() {
        $(this).draggable({start:
            function(){
               //identifies dragged item
            }
         })
     })
     $('.droppable').live('mouseover', function() {
         $(this).droppable({drop: 
             function(){
                //checks to see if it wants dragged item                
             }
          })
     })
});

编辑:

抱歉,如果我不清楚 - 我会尽力澄清:我有一个父页面,其中有一个 div,我使用 jQuery 加载函数加载其他页面。除了导航之外,该父页面基本上是空的。所有操作都在加载到其中的从属页面上进行。关于加载,没有什么奇怪的事情发生 - 页面都加载得很好 - 所以我可以自己查看加载的页面(直接在浏览器中打开它们),或者在它们加载到时查看它们父页面。这就是似乎有些奇怪的地方,阻力起作用但不下降。父页面的加载是通过以下方式完成的:

$('.unit-nav-links').bind('click', function() {
    var $sender = $(this);
    $('.content').fadeOut(200, function() {
        $('.content').load($sender.attr('href'), function () {
            $('.content').fadeIn(200, function() {
                currentIndex = parseInt($sender.attr('data-currentIndex'));
            });
        });
    });
    return false;
})

其中 content 是保存正在加载的页面的 div,href 是正在加载的页面的地址。


编辑:我已经找到了这个问题的解决方案,因此万一有人偶然发现这个问题,结果发现问题在于将

元素拖动到元素上。由于我无法开始猜测的原因,当通过 jQuery 加载调用页面时,这不起作用,尽管拖动

或到上是可以的,所以解决方案只是将图像包装在

标签中,而鲍勃是你的叔叔。至少我希望他是。

I've got a simple jquery setup involving some divs with images and some text which needs to be dragged on to the images. If I run the page on its own, everything is fine. Unfortunately, the way I have things set up, this is an html page which is loaded by jQuery load() into a div on a parent page and when I do this, although the drag works, the drop doesn't. Any ideas? Thanks.

$(document).ready(function () {
    $('.draggable').live('mouseover', function() {
        $(this).draggable({start:
            function(){
               //identifies dragged item
            }
         })
     })
     $('.droppable').live('mouseover', function() {
         $(this).droppable({drop: 
             function(){
                //checks to see if it wants dragged item                
             }
          })
     })
});

Edit:

Sorry if I was unclear - I'll do my best to clarify: I've got a parent page which has a div into which I'm loading other pages, using the jQuery load function. This parent page is largely empty apart from navigation. All the action goes on on the subordinate pages which are being loaded into it. With regard to the loading, there's nothing fancy going on there - the pages are all loading fine - so I can either look at the loaded pages on their own (opening them directly in a browser) or look at them as they're loaded into the parent page. And that's where there seems to be something screwy, with drag working but drop not. The loading on the parent page is done by:

$('.unit-nav-links').bind('click', function() {
    var $sender = $(this);
    $('.content').fadeOut(200, function() {
        $('.content').load($sender.attr('href'), function () {
            $('.content').fadeIn(200, function() {
                currentIndex = parseInt($sender.attr('data-currentIndex'));
            });
        });
    });
    return false;
})

where content is the div holding the page being loaded and href is the address of the page being loaded.


Edit: I've found a solution to this one so in the unlikely event that someone stumbles on this it turns out that the problem was with dragging

elements onto elements. For reasons I can't begin to guess at, when calling the page through jQuery load, this doesn't work, though dragging

onto

or onto is fine, so the solution is just to wrap the images in

tags and Bob's your uncle. At least I hope he is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月寒剑心 2024-12-07 00:13:11

您的鼠标事件都是鼠标悬停。尝试将它们切换为 mousedown 来开始拖动,然后 mouseup 来结束拖动。

Your mouse events are both mouseover. Try switch them to mousedown to start the drag and and mouseup to end it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文