Jquery Draggable保存位置,不同的ID

时间:2016-06-03 14:14:56

标签: jquery jquery-ui-draggable

我试图双击,拖放然后保存到本地存储工作任何人都有一个好主意?

<img ondblclick="init (this.id)" src="http://images.dailytech.com/nimage/G_is_For_Google_New_Logo_Thumb.png" id="goog" class="icons">
<img ondblclick="init (this.id)" src="http://images.dailytech.com/nimage/G_is_For_Google_New_Logo_Thumb.png" id="glo" class="icons">
<img ondblclick="init (this.id)" src="http://images.dailytech.com/nimage/G_is_For_Google_New_Logo_Thumb.png" id="g" class="icons">

var sPositions = localStorage.positions || "{}",
    positions = JSON.parse(sPositions);

$.each(positions, function (id, pos) {
    $("#" + id).css(pos)
})

function init (id) {

    $("#" + id).draggable({
        grid: [ 15, 15 ], 
        stop: function (event, ui) {
           positions[this.id] = ui.position
           localStorage.positions = JSON.stringify(positions)
        }
    })
};

http://jsfiddle.net/caa888/Lyfqwj1c/8/

感谢

0 个答案:

没有答案