Mousemove event not firing on page element or document
Asked Answered
M

6

5

I am trying to use the js slider slick, but the default 'draggable' option does not work when I include the slider code on my site. More specifically, I cannot capture any mousemove events on the slide div, or on the document in my webpage (Chrome).

When run the code locally I have no problem observing the 'mouseup', 'mousemove', and 'mouseup' events, but when I put the slider code into the webpage I am only able to observe the 'mouseup' and 'mousedown' events.

Below is the working local code. If you run it, it will log the mousedown, mousemove, and mouseup events inside the slider div.

When I move the same code to the website I am not able to observe any mousemove events coming from the slider div, or from the document at all. Could there be some js running already that would completely prevent mousemove events from being fired by the page?

<html>
  <head>
      <title>My Now Amazing Webpage</title>

      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.css"/>
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.css"/>
      <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.js"></script>
  </head>
  <body>

  <style>

    #container {
      width: 450px;
      height: 300px;
      margin: 0 auto;
      border: 2px solid black;
    }

  </style>

  <div id="container">
    <div class="your-class">
      <div><img src="http://lorempixel.com/300/300" /></div>
      <div><img src="http://lorempixel.com/300/300" /></div>
      <div><img src="http://lorempixel.com/300/300" /></div>
    </div>
  </div>



  <script type="text/javascript">
    $(document).ready(function(){

        $('.your-class').slick();

        $('.slick-slide').on('mousemove', function(e){
          console.log("mousemove");
        });

        $('.slick-slide').on('mousedown', function(e){
          console.log("mousedown");
        });

        $('.slick-slide').on('mouseup', function(e){
          console.log("mouseup");
        });
    });
  </script>

  </body>
</html>
Mantegna answered 9/6, 2016 at 16:53 Comment(2)
You don't need type="text/javascript".Decaffeinate
Yes, true - thank you.Mantegna
J
14

Not sure if this answers your specific question, but it might be helpful for others that turn up here.

If you're testing using Chrome dev tools (say) and you have a device profile active, then Chrome will emulate touch interaction and not send mousemove events (as would be the case for a phone/tablet where the browser can't tell when the users finger if it's not touching the screen).

If you change the device type from (eg) "Desktop (touch)" to just "Desktop", you'll keep the desired screen size, but gain back the mouse events.

Johppa answered 20/11, 2018 at 3:29 Comment(1)
This was the case when I was working on an Adobe CEP extension!Census
M
4

The problem was that specific chrome tab. I don't know why I was having issues, but refreshing it didn't change anything--but when I loaded the site in an incognito window and a new chrome window it fixed it.

The only thing that was different between the tabs was that the one I was having the issue in had been open for a much longer time (~3-4 hours). I don't know why that would affect anything, but I would love to hear what someone thought if they had any ideas.

Mantegna answered 9/6, 2016 at 22:16 Comment(2)
I was just having the same issue and I'd have wasted a lot of time if I didn't read this. Very peculiar issue (browser bug?).Olivine
sometimes it helps to clear your cache. Just open console and then right-click on your refresh button and 'Empty cache and hard reload'. I usually do this :)Beverie
N
2

Your local code works fine. Grab the event by the document like

$(document).on('mousemove', '.slick-slide', function(){ console.log('mousemove'); });

Check it out in the website.

Nanette answered 9/6, 2016 at 16:59 Comment(2)
Yes my local code did work, it was when I put that on the website that didn't work.Mantegna
It was some problem with the browser --- still don't know what, but I tried it in an incognito tab and the mouseevents worked fine, and then I just did a new normal chrome tab it worked fine. Only having the problem in a chrome tab that was open for more than 3 hours or so.Mantegna
P
2

Most devs experiencing this have their dev console open, and in Chrome this usually changes your input to be in touch mode, where there is no constant cursor as there is on desktops.

Either make your code have different behavior for touch input to get a desired result, or you can add a device type to your dev console session by changing the options shown in the attached screenshot.

enter image description here

Psychoneurosis answered 24/1, 2021 at 22:40 Comment(0)
M
1

This seems to be an issue if you have a responsive mode selected on your Chrome Dev Tools

You can easily resolve it by switching to Desktop like this:

1. Try toggle Device toolbar

Toggle Device toolbar

2. Switch to Desktop mode manually

Add Device Type Select Desktop

Maelstrom answered 3/8, 2022 at 10:16 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewJell
M
0

I had the same issue, I had used a "mousemove" event listener. When running on the live server it was not recording any mouse events onto the console (I had opened my dev tools). But, I closed my dev tools and hovered over the elements, and then opened the dev tools console and it was recorded.

Marrowfat answered 17/2, 2024 at 5:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.