random position boxes on refresh + fix zIndex

master
Tancre 3 years ago
parent 20436b31e6
commit 7c0ddd775b

@ -21,7 +21,7 @@
<h1>windows.open(Welcome)</h1> <h1>windows.open(Welcome)</h1>
<div id="boxes"> <div id="dragZone" class="dragzone">
<div id="program" class="ui-widget-content draggable resizable" style="max-width: 250px; height: 1400px;"> <div id="program" class="ui-widget-content draggable resizable" style="max-width: 250px; height: 1400px;">
<h1>10 Sept 21</h1> <h1>10 Sept 21</h1>

@ -1,14 +1,13 @@
// TODO // TODO
// glyphs // glyphs
// random position
// what buttons where // what buttons where
// colophone // colophone
// a bit more interface // a bit more interface
// DONE // DONE
// Open window icon (on background 'desktop') // Open window icon (on background 'desktop')
// Close window button (on 'window' itself) // Close window button (on 'window' itself)
// random position
let corpi = { let corpi = {
0: { 0: {
@ -37,7 +36,8 @@ $(document).ready(function(){
// Generate divs // Generate divs
Object.values(corpi).forEach(corpus => { Object.values(corpi).forEach(corpus => {
$('#boxes' ).append(`
$('#dragZone' ).append(`
<div class="ui-widget-content draggable resizable" id="${corpus['id']}"> <div class="ui-widget-content draggable resizable" id="${corpus['id']}">
<h1>${corpus['title']}</h1> <h1>${corpus['title']}</h1>
<p>${corpus['content']}</p> <p>${corpus['content']}</p>
@ -49,7 +49,6 @@ $(document).ready(function(){
// Start mouse UI // Start mouse UI
const dragResize = new DragResizeClose(); const dragResize = new DragResizeClose();
}); });
class DragResizeClose { class DragResizeClose {
constructor() { constructor() {
@ -98,16 +97,36 @@ class DragResizeClose {
$( ".draggable" ).each(function() { $( ".draggable" ).each(function() {
let rw = getRndInteger((getWidth())/2-500,(getWidth())/2) let rw = getRndInteger((getWidth())/2-500,(getWidth())/2)
//let rh = getRndInteger(heightDrag-200, heightDrag) //let rh = getRndInteger(heightDrag-200, heightDrag)
$( this ).css("width",rw);
$( this ).css("height", 'auto'); //setDimension
$(this).css("width",rw);
$(this).css("height", 'auto');
//setPosition
let w = window.innerWidth;
let h = window.innerHeight;
if (this.id != 'program'){
let wBox = $(this).css('width');
let hBox = $(this).css('height');
let rX = randomCorrected(h, hBox);
let rY = randomCorrected(w, wBox);
$(this).css("top", rX);
$(this).css("left", rY);
} else {
$(this).css("top", '20px');
$(this).css("right", '20px');
}
}); });
} }
setZindex() { setZindex() {
$('#dragZone div').click(() => { // Setup z-index handler let zIndex = 3;
$('#dragZone div').mousedown(function() { // Setup z-index handler
$(this).addClass('top').removeClass('bottom'); $(this).addClass('top').removeClass('bottom');
$(this).siblings().removeClass('top').addClass('bottom'); $(this).siblings().removeClass('top').addClass('bottom');
$(this).css("z-index", this.zIndex++); $(this).css("z-index", zIndex++);
}); });
} }
@ -133,3 +152,7 @@ class DragResizeClose {
} }
} }
function randomCorrected(sideWindow, sideBox){
var corrected = sideWindow - parseInt(sideBox);
return Math.floor(Math.random() * corrected)
}
Loading…
Cancel
Save