[英]Save Draggable Div Position
i had added a drag and move div to my website, i am using common header for each pages. 我已经将div拖放到我的网站上,我为每个页面使用通用标题。
my drag and move div code as follows: 我的拖放div代码如下:
Script: 脚本:
<script type="text/javascript">
$(function() {
$( "#draggable" ).draggable();
});
</script>
Div: 分区:
<div class="student_avatar_header" id="draggable" title="Drag and Move...">
Some texts...
</div>
CSS: 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;
}
this drag and move function working fine, what my question is i had added this draggable Div to my header so it will appear even visit any pages my website, i just want to set a cookie function or what possible for remember last position where it dragged. 此拖放功能正常工作,我的问题是我已将此可拖动Div添加到标题中,因此即使访问我的网站的任何页面,它也将显示,我只想设置Cookie函数或记住它拖动到的最后位置的可能性。 for example now i am here
home
page, i just drag my div to page bottom, but when i go to about
page this div appear not previous position, its appear default position. 例如现在我在这里
home
,我只是将div拖动到页面底部,但是当我转到about
该页面时,该div不在以前的位置,而是它的默认位置。 i need it display previous position even i visit any pages my website, 即使我访问我的网站的任何页面,我也需要它显示以前的位置,
NOTE: my website have above 35 pages. 注意: 我的网站有35页以上。
any idea.? 任何想法。?
thanks... 谢谢...
Have a look on the following code : 看下面的代码:
$("#draggable").draggable({
stop: function(event, ui) {
$.cookie("elementIDCookie", ui.position);
}
});
To re-position the element when the user returns: 在用户返回时重新定位元素:
$("#draggable").css( { "left" : $.cookie("elementIDCookie").left, "top" : $.cookie("elementIDCookie").top });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.