From 72db5bef4047bc77da909222745c0bee60d33301 Mon Sep 17 00:00:00 2001 From: Tancre Date: Mon, 30 Aug 2021 14:40:57 +0200 Subject: [PATCH] fix random position height to not overlap title --- scripts/App.js | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/scripts/App.js b/scripts/App.js index 0a63b18..2888b8b 100644 --- a/scripts/App.js +++ b/scripts/App.js @@ -52,7 +52,6 @@ $(document).ready(function(){ }); class DragResizeClose { constructor() { - this.zIndex = 3; this.drag(); this.setDraggables(); this.setZindex(); @@ -61,9 +60,7 @@ class DragResizeClose { } drag() { - $('.draggable').draggable({ containment: "window" }, { // Setup dragging and containment - start: (event, ui) => $(this).css("z-index", this.zIndex++) // Initialize z-index - }); + $('.draggable').draggable({ containment: "window" }); } setDraggables() { @@ -78,22 +75,6 @@ class DragResizeClose { ); } - //let widthDrag = (getWidth())/2; - - // function getHeight() { - // return Math.max( - // document.body.scrollHeight, - // document.documentElement.scrollHeight, - // document.body.offsetHeight, - // document.documentElement.offsetHeight, - // document.documentElement.clientHeight - // ); - // } - - // let heightDrag = (getHeight())/2; - - const getRndInteger = (min, max) => Math.floor(Math.random() * (max - min + 1) ) + min; - $( ".draggable" ).each(function() { let rw = getRndInteger((getWidth())/2-500,(getWidth())/2) //let rh = getRndInteger(heightDrag-200, heightDrag) @@ -109,8 +90,8 @@ class DragResizeClose { if (this.id != 'program'){ let wBox = $(this).css('width'); let hBox = $(this).css('height'); - let rX = randomCorrected(h, hBox); - let rY = randomCorrected(w, wBox); + let rX = randomCorrectedHeight(h, hBox); + let rY = randomCorrectedWidth(w, wBox); $(this).css("top", rX); $(this).css("left", rY); } else { @@ -152,7 +133,14 @@ class DragResizeClose { } } -function randomCorrected(sideWindow, sideBox){ - var corrected = sideWindow - parseInt(sideBox); +const randomCorrectedWidth = (sizeWindow, sizeBox) => { + var corrected = sizeWindow - parseInt(sizeBox); return Math.floor(Math.random() * corrected) -} \ No newline at end of file +} + +const randomCorrectedHeight = (sizeWindow, sizeBox) => { + var corrected = sizeWindow - parseInt(sizeBox); + return getRndInteger(105, corrected) +} + +const getRndInteger = (min, max) => Math.floor(Math.random() * (max - min + 1) ) + min; \ No newline at end of file