代码之家  ›  专栏  ›  技术社区  ›  Triwahyu Pamungkas Pribadi

如何在可拖动停止时获取目标/类名

  •  0
  • Triwahyu Pamungkas Pribadi  · 技术社区  · 7 年前

    我使用Jquery UI可拖动, 当可拖动列表菜单时,我想在收藏夹菜单上添加菜单。。。 I使用选项 appendTo ,但问题是,当我拖动到收藏夹容器时,如何将菜单添加到收藏夹菜单。。。

    对不起,我的英语不好。。。

    enter image description here

    2 回复  |  直到 7 年前
        1
  •  0
  •   Munkhdelger Tumenbayar    7 年前
    $("YourSelector").draggable(
            {
                start: function(event, ui)
                {
                    //This Occurs when drag start
                    selectedClass = $(this).attr('data-value');
                    console.log(selectedValue);
                },
                stop: function() { 
                    //This Occurs when drag stop
                    selectedClass = $(this).attr('data-value');
                    console.log(selectedValue);}
            });
    
        2
  •  0
  •   Triwahyu Pamungkas Pribadi    7 年前
    $(".navbar-menu").draggable({
                appendTo: ".navbar-favoritebody ul",
                axis: "y",
                containment: ".navbar-left",
                handle: "a:not([data-disabled]):not([data-type='favorite']):not(:contains('Dashboard'))",
                helper: "clone",
                start: function(ev, ui) {
                    $("body").prepend("<div class=\"ondrag\"></div>");
                    var _this = $(this);
                    _this.find("a").attr("data-href","favorite/create");
                },
                drag: function(ev, ui) {},
                stop: function(ev, ui) {
                    $(".ondrag").remove();
                    var _this = $(this),
                        desc = parsing.toUpper(_this.find("a").attr("data-slug").replace(/\-/g, " "), 2);
    
                    var target = $(event.target);
                    console.log(target.prop('className'));
                    if(target.prop("className") == "navbar-favoritebody") {
                        $.ajax({
                            type: "POST",
                            url: location.pathname+"?r="+_this.find("a").attr("data-href"),
                            data: {
                             "Favorite[menu_id]": _this.find("a").attr("data-menu"),
                            },
                            dataType: "text",
                            error: function(xhr, errors, message) {
                            console.log(xhr, errors, message);
                            },
                            beforeSend: function() {
                            navigasi.process("load");
                            },
                            success: function(data) {
                                if(!$.trim(data)) {
                                    notification.open("danger", "Menu "+ desc +" sudah ada di Favorite.", 2000);
                                } else {
                                    $(".navbar-favoritebody").html(data);
                                    notification.open("success", "Menu "+ desc +" berhasil ditambah ke Favorite.", 2000);
                                }
                            },
                            complete: function() {
                            navigasi.process("destroy");
                                _this.find("a").removeAttr("data-href");
                             }
                         });
                     }
                },