我正在尝试制作我的第一个 Firefox 扩展,它将新的标签页替换为更像 Chrome 的标签页。其中一项功能是“最常访问的网站”的图 block ,您可以拖放以重新排序。我将它们拖放,但我不知道如何保存 DIV 的新位置。
这是我正在使用的脚本:
$(document).ready(function(){
jQuery.fn.redswap = function(options){
var selectedItems=this;
redsettings = jQuery.extend({
speed:"Medium",
opacity:0.7
}, options);
$(selectedItems).mouseover(function(){
$(selectedItems).disableSelection();
$(selectedItems).droppable({
drop: function(event, ui) {
dropindex=$(selectedItems).index(this);
var dragposition=$(selectedItems[dragindex]).position();
var dropposition=$(selectedItems[dropindex]).position();
withDifference=parseInt(dragposition.left)-parseInt(dropposition.left);
heightDifference=parseInt(dragposition.top)-parseInt(dropposition.top);
$(selectedItems[dropindex]).animate({
left:'+='+withDifference,
top:'+='+heightDifference
},redsettings.speed,function(){
});
$(selectedItems[dragindex]).animate({
left:'+='+(withDifference*(-1)),
top:'+='+(heightDifference*(-1))
},redsettings.speed,function(){
//Complete
});
},
});
$(this).draggable({
opacity:redsettings.opacity,
helper: 'clone',
containment: 'parent',
scroll: false,
drag:function(event, ui){
dragindex=$(selectedItems).index(this);
}
});
});
};
});
// Settings
$(document).ready(function(){
$("#wrapper").tabs();
$("div[id*='box']").redswap({
speed:'slow',
opacity:.75
});
});
这是我的 HTML:
<div id="1box" class="item">
<a href="http://www.google.com/reader/view"><img src="thumbs/01.png" border="0" />
<h1>Google Reader</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>
<div id="2box" class="item">
<a href="https://mail.google.com/"><img src="thumbs/02.png" border="0" />
<h1>Gmail</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>
<div id="3box" class="item">
<a href="http://calendar.google.com/"><img src="thumbs/03.png" border="0" />
<h1>Google Calendar</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>
<div id="4box" class="item">
<a href="http://www.twitter.com/"><img src="thumbs/04.png" border="0" />
<h1>Twitter</a></h1><a href="#" class="x"></a><a href="#" class="tack"></a>
</div>
HTML 尚未最终确定,但可以进行拖放操作。知道如何保存 DIV 的新顺序,以便当我关闭并再次打开它时,它是新配置吗?如果这个脚本不能完成,那么我很高兴被指向一个新版本。
请记住,我对 JavaScript 非常陌生,所以请像对待白痴一样对待我:)
此外,如果您有兴趣帮助我完成编码部分,请给我发送消息。
最佳答案
听起来您正在寻找某种存储来包含您的序列信息。
本文 Stack Overflow question 讨论了适用于 Firefox 扩展的三种方法。
我认为 SQLite 或文件系统选项都适合您的应用程序。
关于javascript - 保存位置的可排序 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5267371/