Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a method which I quickly wrote, this does not use jQuery though.</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Example Slider&lt;/title&gt; &lt;style type="text/css"&gt; #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; } &lt;/style&gt; &lt;script type="text/javascript"&gt; 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) &gt;= document.getElementById('bar2').offsetWidth) { release(); document.getElementById('bar1').style.width = document.getElementById('bar2').offsetWidth + "px"; } else if (mouse_x &lt;= 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"; } } &lt;/script&gt; &lt;/head&gt; &lt;body onmouseup="javascript:release();"&gt; &lt;div id="bar1"&gt; &lt;div id="slider" onmousedown="javascript:drag();"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="bar2"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>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. </p> <p>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.</p> <p>Hopefully this was helpful in some way :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload