phdphd Posted January 3, 2019 Share Posted January 3, 2019 Hi all, I want to make a div follow the mouse vertical position, with some fading effect. It turns out that the code does not stop running despite the "off" method. I would like to make it run just once every time the mouse is moved. Thanks! $(document).on('mousemove', function(e){ $( "#nav2" ).delay(2000).fadeIn(1000).delay(2000).fadeOut(1000); $('#nav2').css({top:y = e.pageY}); $('#nav2').off('mousemove'); }); Quote Link to comment https://forums.phpfreaks.com/topic/308099-jquery-fire-event-on-mousemove-only-once/ Share on other sites More sharing options...
requinix Posted January 3, 2019 Share Posted January 3, 2019 If you want to "off" an event then you have to do it with the event handler you actually attached. When you change that you'll find out that it's not all working quite as you want... Quote Link to comment https://forums.phpfreaks.com/topic/308099-jquery-fire-event-on-mousemove-only-once/#findComment-1563253 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.