代码之家  ›  专栏  ›  技术社区  ›  James Thompson

jquery-多个重叠的下拉列表会导致不可预测的下拉列表

  •  3
  • James Thompson  · 技术社区  · 14 年前

    我有一个可拖动的,它被放置在一个重叠的可拖放等距网格上。Droppables是灰色瓷砖、img标签,看起来像附加的第一个图像。当可拖动对象覆盖它们时,它们被设置为突出显示蓝色。

    以下是Droppable的源代码:

            $(".sprite").droppable({
                drop: function(event,ui) {
                    object_id = ui.draggable.attr("id").replace("sprite_","");
                    set_action('move_object',$(this).attr("id"));
                    set_target(object_id);
                    ui.draggable.removeClass("holding");
                },
                over: function(event, ui) {
                    $(this).attr("src",$(this).attr("src").replace('.png','-hover-blue.png'));
                },
                out: function(event, ui) {
                    $(this).attr("src",$(this).attr("src").replace('-hover-blue.png','.png'));
                },
                tolerance: 'pointer'
            });
    

    基本上,我希望a)一次突出显示一个图块,b)让突出显示的图块成为对象放置的图块。

    我试过各种各样的宽容,但都没有用。

    图像:

    i.imgur.com/dgx9x.png

    i.imgur.com/vb1d9.png

    1 回复  |  直到 14 年前
        1
  •  2
  •   generalhenry    14 年前

    当可拖动移动到可拖动上时,应停用所有其他可拖动并激活当前可拖动。然后很容易产生掉电效应,即主动掉电效应。

    在over函数中

    $(".sprite").not($(this)).removeClass("over")
       .each(function(){
         $(this).attr("src",$(this).attr("src").replace('-hover-blue.png','.png'));
       });
    $(this).addClass("over");
    

    然后,直接将$(this)替换为$(“.over”)。