Alright everyone, is there a way to have 2 divs taking up 50% of the screen and have a bar in the middle so you can drag it and make the left 40% and the right 60% and vice versa.
I hope to be able to do this jquery.
Here's a method which I quickly wrote, this does not use jQuery though.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example Slider</title>
<style type="text/css">
#bar1 {
position: absolute;
background: red;
height: 250px;
width: 400px;
z-index: 1;
}
#bar2 {
position: absolute;
background: green;
height: 250px;
width: 800px;
}
#slider {
position: relative;
background: blue;
height: 100%;
width: 10px;
float: right;
}
</style>
<script type="text/javascript">
var down = false;
var mouse_x;
var interval;
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = get_mouse_x;
function get_mouse_x(e) {
if (IE)
mouse_x = event.clientX;
else
mouse_x = e.pageX;
}
function drag() {
interval = setInterval("update()", 1);
}
function release() {
clearInterval(interval);
}
function update() {
if ((mouse_x - document.getElementById('bar1').offsetLeft) >= document.getElementById('bar2').offsetWidth) {
release();
document.getElementById('bar1').style.width = document.getElementById('bar2').offsetWidth + "px";
} else if (mouse_x <= document.getElementById('bar1').offsetLeft) {
release();
document.getElementById('bar1').style.width = document.getElementById('bar1').offsetLeft + "px";
} else {
document.getElementById('bar1').style.width = (mouse_x - document.getElementById('bar1').offsetLeft) + "px";
}
}
</script>
</head>
<body onmouseup="javascript:release();">
<div id="bar1">
<div id="slider" onmousedown="javascript:drag();"> </div>
</div>
<div id="bar2"></div>
</body>
</html>
I don't recommend you use that on your website, instead learn from it or improve so that it is completely stable. But hopefully that gives you an idea on how to tackle this problem.
Also there's a bug in IE where, after sliding, it does not lose focus from the slider div. So this means that when you re-slide it, it doesn't release properly. To avoid this: after initial sliding, focus something else, and then slide again. Other then that it works fine.
Hopefully this was helpful in some way :)