Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><b>I've made you a working example:</b> <a href="http://jsfiddle.net/zbfUq/37/" rel="nofollow">http://jsfiddle.net/zbfUq/37/</a></p> <p>Essentially you have record the mouse position in the <code>onmousemove</code> event handler, but not actually move the line there straight away.</p> <p>You then run a timer which checks every so often (every 10 milliseconds in my example), and moves the line closer to the mouse position.</p> <p>In the <code>onmouseover</code> event, I set the line position to the mouse position, and set the timer going.</p> <p>In the <code>onmouseout</code> event I clear the timer, and set the line position back to 0 (you could also hide the line).</p> <p>The <code>updatepos</code> function first checks how far away the line is from the mouse position. If it is less than 1px away, it simply moves the line to the mouse position. If it is more than 1px away, it moves is closer at a speed proportional to the distance away it is (if the line is further from the mouse, it moves towards it quicker).</p> <p><b>Javascript code</b></p> <pre><code>(function() { var selectline = document.getElementById('selection_line'); var container = document.getElementById('page_content'); var mouseX = 0; var lineX = 0; var linetimer; var updatepos = function () { var speed, distance; distance = Math.abs(mouseX - lineX); if (distance &lt; 1) { lineX = mouseX; } else { speed = Math.round( distance / 10, 0 ); speed = speed &gt;= 1 ? speed : 1; lineX = (lineX &lt; mouseX) ? lineX + speed : lineX - speed; } selectline.style.left = lineX + 'px'; } $(container).on("mouseover", function(e) { lineX = mouseX; selectline.style.left = lineX + 'px'; linetimer = setInterval(updatepos, 10); }); $(container).on('mousemove', function(e) { mouseX = e.pageX; console.log(mouseX); }); $(container).on("mouseout", function(e) { clearTimeout(linetimer); lineX = 0; selectline.style.left = LineX + 'px'; }); })();​ </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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