From 083cb6e619d8cf64d32caadbc267532009d0befd Mon Sep 17 00:00:00 2001 From: Cutls Date: Sun, 10 Mar 2019 00:03:02 +0900 Subject: [PATCH] To fix position of toot box --- app/css/tl.css | 2 +- app/js/ui/post-box.js | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/css/tl.css b/app/css/tl.css index 0dde0048..7fd03b9b 100644 --- a/app/css/tl.css +++ b/app/css/tl.css @@ -518,4 +518,4 @@ p:not(:last-child){ .cvo-anime { animation-duration: 0.1s; animation-name: fadeInDown; -} \ No newline at end of file +} diff --git a/app/js/ui/post-box.js b/app/js/ui/post-box.js index 723eeea9..e9fc1d50 100644 --- a/app/js/ui/post-box.js +++ b/app/js/ui/post-box.js @@ -19,17 +19,40 @@ function show() { $("#post-box").addClass("appear") $("#textarea").focus(); console.log("show"+localStorage.getItem("postbox-left")); - $('#post-box').css("left",localStorage.getItem("postbox-left")+"px") - $('#post-box').css("top",localStorage.getItem("postbox-top")+"px") + var left=localStorage.getItem("postbox-left"); + 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(); } $(function() { $( "#post-box" ).draggable({handle: "#post-bar", stop: function() { - console.log("stopped"); - localStorage.setItem("postbox-left",$('#post-box').offset().left); - localStorage.setItem("postbox-top",$('#post-box').offset().top); + var left=$('#post-box').offset().left; + if(left>$('body').width()-$('#post-box').width()){ + 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); } }); });