【问题标题】:Sortable jQuery mobile list; with local storage可排序的 jQuery 移动列表;带本地存储
【发布时间】:2013-12-22 14:53:34
【问题描述】:

我有一个 jQuery 移动列表,它具有滑动删除功能并在本地存储首选项。我正在尝试实现重新排序列表项并将其存储在同一个数组中的功能,请帮助! 这是我的小提琴:http://jsfiddle.net/f18nfz/nUSUB/2/

所以函数可能类似于 (http://jsfiddle.net/maziar/P2XDc/):

function moveUp(item) {
    var prev = item.prev();
    if (prev.length == 0)
        return;
    prev.css('z-index', 999).css('position','relative').animate({ top: item.height() }, 250);
    item.css('z-index', 1000).css('position', 'relative').animate({ top: '-' + prev.height() }, 300, function () {
        prev.css('z-index', '').css('top', '').css('position', '');
        item.css('z-index', '').css('top', '').css('position', '');
        item.insertBefore(prev);
    });
}
function moveDown(item) {
    var next = item.next();
    if (next.length == 0)
        return;
    next.css('z-index', 999).css('position', 'relative').animate({ top: '-' + item.height() }, 250);
    item.css('z-index', 1000).css('position', 'relative').animate({ top: next.height() }, 300, function () {
        next.css('z-index', '').css('top', '').css('position', '');
        item.css('z-index', '').css('top', '').css('position', '');
        item.insertAfter(next);
    });
}

$(".FieldContainer").sortable({ items: ".OrderingField", distance: 10 });
$('button').click(function() { 
    var btn = $(this);
    var val = btn.val();
    if (val == 'up')
        moveUp(btn.parents('.OrderingField'));
    else
        moveDown(btn.parents('.OrderingField'));
});

【问题讨论】:

    标签: javascript jquery-mobile local-storage jquery-mobile-listview


    【解决方案1】:

    这是一个使用 jQuery Mobile 的可排序拖放列表的好例子:http://jsfiddle.net/sidonaldson/pes2d/

    <div data-role="page" id="page1">
        <div data-role="content">
            <ul data-role="listview" data-divider-theme="b" data-inset="true">
                <li data-role="list-divider" role="heading">Re-order</li>
                <li data-theme="c">1</li>
                <li data-theme="c">2</li>
                <li data-theme="c">3</li>
                <li data-theme="c">4</li>
                <li data-theme="c">5</li>
                <li data-theme="c">6</li>
                <li data-theme="c">7</li>
            </ul>
            <a data-role="button">Submit</a>
        </div>
    </div>
    
    $(document).ready(function(e) {
        $('li').removeClass('ui-corner-bottom');
        $('ul')
            .addClass('ui-corner-top')
            .removeClass('ui-corner-all')
            .sortable({
                'containment': 'parent',
                'opacity': 0.6,
                update: function(event, ui) {
                    alert("dropped");
                }
            });
    });
    

    【讨论】:

    • 由于我的列表很长,您需要滚动浏览它,我想要按钮,或者如果我可以在每个可拖动的列表项上只有一个图标或按钮可以工作......跨度>
    猜你喜欢
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    相关资源
    最近更新 更多