【问题标题】:jQuery UI draggable and sortable not workingjQuery UI 可拖动和可排序不起作用
【发布时间】:2015-11-23 17:02:14
【问题描述】:

我正在尝试让可拖动和可排序以协同工作,但没有运气。

查看此gist 获取 html 代码

相关的 javascript 是:

function makeDraggable(theID) {
$('ul#elements > li.element').each(function() { // TODO: also for templates
    $(this).draggable({
        helper: function() {
            return $('<div style="height: 100px; width: 300px; background: #F9FAFA; box-shadow: 5px 5px 1px rgba(0,0,0,0.1); text-align: center; line-height: 100px; font-size: 28px; color: #16A085"><span class="fui-list"></span></div>');
        },
        revert: 'invalid',
        appendTo: 'body',
        connectToSortable: theID,
        stop: function() {
            pageEmpty();
            allEmpty();
        },
        start: function() {
            // switch to block mode
            $('input:radio[name=mode]').parent().addClass('disabled');
            $('input:radio[name=mode]#modeBlock').radiocheck('check');

            // deactivate design mode
            $('#pageList ul li iframe').each(function() {
                this.contentDocument.designMode = "off";
            });
        }
    });
});
$('#elements li a').each(function() {
    $(this).unbind('click').bind('click', function(e) {
        e.preventDefault();
    });
});
}
function makeSortable(el) {

el.sortable({
    revert: true,
    tolerance: 'pointer',
    placeholder: "drop-hover",
    beforeStop: function(event, ui) {
        console.log('beforeStop');
        var attr = ui.item.attr('data-frames');
        if (typeof attr !== typeof undefined && attr !== false) { // template, build it
            $('#start').hide();

            // clear out old possible frames
            $('#pageList ul:visible li').each(function() {
                $(this).remove();
            });

            // create the new frames
            frameIDs = ui.item.attr('data-frames').split('-');
            heights = ui.item.attr('data-heights').split('-');
            urls = ui.item.attr('data-originalurls').split('-');
            for (x = 0; x < frameIDs.length; x++) {
                toInsert = $('<li><iframe src="' + laroute.route('api.sites.getframe', {id: frameIDs[x]}) + '" frameborder="0" scrolling="0" data-originalurl="' + urls[x] + '"></li>');
                $('#pageList ul:visible').append(toInsert);
                theHeight = heights[x];
                toInsert.find('iframe').uniqueId().height(theHeight + "px");
                toInsert.height(theHeight + "px");
                // add a delete button
                delButton = $('<button type="button" class="btn btn-danger deleteBlock"><span class="fui-trash"></span> remove</button>');
                resetButton = $('<button type="button" class="btn btn-warning resetBlock"><i class="fa fa-refresh"></i> reset</button>');
                htmlButton = $('<button type="button" class="btn btn-inverse htmlBlock"><i class="fa fa-code"></i> source</button>');
                frameCover = $('<div class="frameCover"></div>');
                frameCover.append(delButton);
                frameCover.append(resetButton);
                frameCover.append(htmlButton);
                toInsert.append(frameCover);

                // dropped element, so we've got pending changes
                setPendingChanges(true);

                // setup editor events
                toInsert.find('iframe').load(function() {
                    setEditorEvents($(this));
                    heightAdjustment($(this).attr('id'), true);
                });
                allEmpty();
            }

            // set the tempateID
            templateID = ui.item.attr('data-pageid');

            // make sure nothing gets dropped in the list
            ui.item.html(null);

            // delete drag place holder
            $('body .ui-sortable-helper').remove();
        } else {
            alert('imagge');
            if (ui.item.find('.frameCover > button').size() == 0) {
                // image thumbnails
                console.log(ui.item);
                theHeight = ui.item.find('img').attr('data-height');

                ui.item.html('<iframe src="' + ui.item.find('img').attr('data-srcc') + '" scrolling="no" data-originalurl="' + ui.item.find('img').attr('data-srcc') + '" frameborder="0"><iframe>');

                ui.item.find('iframe').uniqueId();
                ui.item.find('iframe').height(theHeight + "px");
                ui.item.find('iframe').css('background', '#ffffff url(' + baseUrl + 'images/loading.gif) 50% 50% no-repeat');
                ui.item.find('iframe').load(function() {
                    heightAdjustment(ui.item.find('iframe').attr('id'), true);
                });

                // add a delete button
                delButton = $('<button type="button" class="btn btn-danger deleteBlock"><span class="fui-trash"></span> remove</button>');
                resetButton = $('<button type="button" class="btn btn-warning resetBlock"><i class="fa fa-refresh"></i> reset</button>');
                htmlButton = $('<button type="button" class="btn btn-inverse htmlBlock"><i class="fa fa-code"></i> source</button>');
                frameCover = $('<div class="frameCover"></div>');
                frameCover.append(delButton);
                frameCover.append(resetButton);
                frameCover.append(htmlButton);
                ui.item.append(frameCover);

                // dropped element, so we've got pending changes
                setPendingChanges(true);
            } else {
                //sorted
                ui.item.find('iframe').load(function() {
                    $(this).contents().find(pageContainer).html(frameContents)
                })
            }
        }
    },
    stop: function() {},
    start: function(event, ui) {
        if (ui.item.find('.frameCover').size() != 0) {
            frameContents = ui.item.find('iframe').contents().find(pageContainer).html();
        }
    },
    over: function() {
        $('#start').hide();
    }
});
}

makeSortable($('#page1'));
makeDraggable('#page1');

我把所有的 html 都放了,因为当我只提取相关部分时,它开箱即用,但当 as 不起作用时。

有人能指出我做错了什么吗?我已经搜索、尝试、寻找 3 天了,但没有运气。

更新 1

从 gist 中去除 uselees html,修正问题的代码语法

我注意到问题可能是可排序的不知道可拖动的悬停它(或相反,可拖动的不知道悬停可排序)

【问题讨论】:

    标签: jquery jquery-ui drag-and-drop


    【解决方案1】:

    自己发现问题,Flat-UI js 和 jQuery-UI js 冲突,重新排序includes就可以解决问题。

    错误:(导致冲突)

    jquery
    jquery-ui
    flat-ui
    

    正确:(冲突消失)

    jquery
    flat-ui
    jquery-ui
    

    请注意,这些脚本主要包含在3rdparty.js 中(与Gulp 混合使用)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-11
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      • 2013-08-26
      • 1970-01-01
      相关资源
      最近更新 更多