Simple Desktop - NON STABLE
by Kevin Pliester
HTML
<body>
<div id="desktop">
<div id="window" class="">
<div class="window-header"><a href="javascript:void(0);" id="close_window"><span></span></a>
<a href="javascript:void(0);" id="hide_window"><span></span></a>
<a href="javascript:void(0);" id="maximize_window"><span></span></a>
</div>
<div class="window-content"></div>
</div>
<div id="nav">
<div class="nav-item"><a href="javascript:void(0);" id="show_window">Window</a>
</div>
</div>
</div>
</body>
CSS
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
position: relative;
}
#desktop {
display: block;
position: fixed;
height: 100%;
width: 100%;
overflow: hidden;
background: #ea6e6e;
z-index: 0;
}
#window {
width: 600px;
margin: 5% auto;
display: block;
box-shadow: 0px 0px 5px rgba(0,0,0,.5);
}
.window-m {
min-width: 100% !important;
height: 100% !important;
margin: 0 auto !important;
position: absolute;
top: 0:
left: 0;
}
.window-c {
display: none !important;
}
.window-h {
display: none !important;
}
.window-s {
display: block !important;
}
#window .window-header {
background: #fff;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
padding: 5px;
}
#window .window-content {
background: #39404a;
min-height: 350px;
color: #4f5660;
padding: 5px;
}
#nav {
position: absolute;
bottom: 0;
display: block;
width: 100%;
background: #fff;
border-top: 1px solid #000;
}
.nav-item a {
color: #333;
text-decoration: none;
border-right: 1px solid #000;
padding: 10px 15px;
display: inline-block;
}
.nav-item a:hover {
background: #e5e5e5;
}
#close_window span {
background: #ff5450;
border-radius: 50%;
height: 15px;
width: 15px;
display: inline-block;
}
#hide_window span {
background: #fccb30;
border-radius: 50%;
height: 15px;
width: 15px;
display: inline-block;
}
#maximize_window span {
background: #7dc410;
border-radius: 50%;
height: 15px;
width: 15px;
display: inline-block;
}
JavaScript
$('#close_window').on('click', function () {
$('#window').toggleClass('window-h');
});
$('#show_window').on('click', function () {
$('#window').toggleClass('window-s');
});
$('#hide_window').on('click', function () {
$('#window').toggleClass('window-h');
});
$('#maximize_window').on('click', function () {
$('#window').toggleClass('window-m');
});
(function ($) {
$.fn.drags = function (opt) {
opt = $.extend({
handle: "",
cursor: "move"
}, opt);
if (opt.handle === "") {
var $el = this;
} else {
var $el = this.find(opt.handle);
}
return $el.css('cursor', opt.cursor).on("mousedown", function (e) {
if (opt.handle === "") {
var $drag = $(this).addClass('draggable');
} else {
var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
}
var z_idx = $drag.css('z-index'),
drg_h = $drag.outerHeight(),
drg_w = $drag.outerWidth(),
pos_y = $drag.offset().top + drg_h - e.pageY,
pos_x = $drag.offset().left + drg_w - e.pageX;
$drag.css('z-index', 1000).parents().on("mousemove", function (e) {
$('.draggable').offset({
top: e.pageY + pos_y - drg_h,
left: e.pageX + pos_x - drg_w
}).on("mouseup", function () {
$(this).removeClass('draggable').css('z-index', z_idx);
});
});
e.preventDefault(); // disable selection
}).on("mouseup", function () {
if (opt.handle === "") {
$(this).removeClass('draggable');
} else {
$(this).removeClass('active-handle').parent().removeClass('draggable');
}
});
}
})(jQuery);
$('#window').drags();