我已经将div拖放到我的网站上,我为每个页面使用通用标题。
我的拖放div代码如下:
脚本:
<script type="text/javascript">
$(function() {
$( "#draggable" ).draggable();
});
</script>
分区:
<div class="student_avatar_header" id="draggable" title="Drag and Move...">
Some texts...
</div>
CSS:
.student_avatar_header {
width: 100px;
height: 100px;
position: absolute;
left: 10px;
top: 20px;
border-radius: 250px;
z-index: 9998;
box-shadow: 2px 2px 12px #008abc;
cursor: move;
}
此拖放功能正常工作,我的问题是我已将此可拖动Div添加到标题中,因此即使访问我的网站的任何页面它也将显示,我只想设置Cookie函数或记住它拖动到的最后位置的可能性。例如,现在我在
home
页面上,我只是将div拖动到页面底部,但是当我转到about
页面时,该div不在以前的位置,而是默认位置。即使我访问我的网站的任何页面,我也需要它显示以前的位置,注意:我的网站有35页以上。
任何想法。?
谢谢...
最佳答案
看下面的代码:
$("#draggable").draggable({
stop: function(event, ui) {
$.cookie("elementIDCookie", ui.position);
}
});
在用户返回时重新定位元素:
$("#draggable").css( { "left" : $.cookie("elementIDCookie").left, "top" : $.cookie("elementIDCookie").top });