Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery, animate div when mouse is near left side
    primarykey
    data
    text
    <p>I am trying to create an menu that will be visible when the mouse is near the left of the viewport (say till 100px from the left, show menu otherwise hide). It should work a bit like the Windows 8 charms bar.</p> <p>I have the following already, but it is not really working well.</p> <pre><code>var mouse_position; //GET MOUSE POSITION $(document).mousemove(function (mouse_pointer) { //$("body").on("mousemove", function(mouse_pointer) { //console.log(mouse_pointer.pageX - $(window).scrollLeft()); //mouse_position = mouse_pointer.pageX - $(window).scrollLeft(); mouse_position = mouse_pointer.clientX; //console.log(mouse_position); if (mouse_position &lt;= 100 &amp;&amp; !$("#cms_bar").is(":visible")) { //SLIDE IN MENU $('#cms_bar').show().animate({ width: '100px' }), 500; console.log('menu shown'); } else if (mouse_position &gt; 100 &amp;&amp; $("#cms_bar").is(":visible")) { $('#cms_bar').animate({ width: '0px' }, 500, function () { $(this).hide(); console.log('menu hidden'); }); } }); </code></pre> <p>Clearly I am doing something wrong.</p> <p><strong>EDIT</strong></p> <pre><code>var mouse_position; //GET MOUSE POSITION $(document).mousemove(function(mouse_pointer) { //$("body").on("mousemove", function(mouse_pointer) { //console.log(mouse_pointer.pageX - $(window).scrollLeft()); //mouse_position = mouse_pointer.pageX - $(window).scrollLeft(); mouse_position = mouse_pointer.clientX; //console.log(mouse_position); if (mouse_position &lt;= 100 &amp;&amp; !$("#cms_bar").is(":visible")) { //SLIDE IN MENU $('#cms_bar').stop().show().animate({width: '100px'}), 300; console.log('menu shown'); } else if (mouse_position &gt; 100 &amp;&amp; $("#cms_bar").is(":visible")) { $('#cms_bar').stop().animate({ width: '0px' }, 300, function() { //$(this).hide(); $(this).css("display","none") console.log('menu hidden'); }); } }); </code></pre> <p>Seems that above edit does a bit more, the problem was / is that when hiding the menu, the animation must be completed. If not and you where again with your mouse &lt; 100 then it got stuck and nothing was shown.</p> <p>Maybe someone has a smoother solution ?</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. This table or related slice is empty.
    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