To fix position of toot box

This commit is contained in:
Cutls 2019-03-10 00:03:02 +09:00
parent ba018b8568
commit 083cb6e619
2 changed files with 29 additions and 6 deletions

View File

@ -19,17 +19,40 @@ function show() {
$("#post-box").addClass("appear") $("#post-box").addClass("appear")
$("#textarea").focus(); $("#textarea").focus();
console.log("show"+localStorage.getItem("postbox-left")); console.log("show"+localStorage.getItem("postbox-left"));
$('#post-box').css("left",localStorage.getItem("postbox-left")+"px") var left=localStorage.getItem("postbox-left");
$('#post-box').css("top",localStorage.getItem("postbox-top")+"px") if(left>$('body').width()-$('#post-box').width()){
left=$('body').width()-$('#post-box').width();
}else if(left<0){
left=0;
}
var top=localStorage.getItem("postbox-top");
if(top>$('body').height()-$('#post-box').height()){
top=$('body').height()-$('#post-box').height();
}else if(top<0){
top=0;
}
$('#post-box').css("left",left+"px")
$('#post-box').css("top",top+"px")
$('#post-box').fadeIn(); $('#post-box').fadeIn();
} }
$(function() { $(function() {
$( "#post-box" ).draggable({handle: "#post-bar", $( "#post-box" ).draggable({handle: "#post-bar",
stop: function() { stop: function() {
console.log("stopped"); var left=$('#post-box').offset().left;
localStorage.setItem("postbox-left",$('#post-box').offset().left); if(left>$('body').width()-$('#post-box').width()){
localStorage.setItem("postbox-top",$('#post-box').offset().top); left=$('body').width()-$('#post-box').width();
}else if(left<0){
left=0;
}
var top=$('#post-box').offset().top;
if(top>$('body').height()-$('#post-box').height()){
top=$('body').height()-$('#post-box').height();
}else if(top<0){
top=0;
}
localStorage.setItem("postbox-left",left);
localStorage.setItem("postbox-top",top);
} }
}); });
}); });