mousemove

How can I get the mouse coordinates relative to a parent div? Javascript

99封情书 提交于 2019-12-03 10:02:17
I currently have a div structured with other elements inside of it. Something similar to below; <div id="container" style="position: relative; width: 500px; height: 500px;"> <div style="position: absolute; left: 50px; top: 50px;"></div> <div style="position: absolute; left: 100px; top: 100px;"></div> </div> I am trying to get the mouse position relative to the div with the id container . So far I have this; function onMousemove(event) { x = event.offsetX; y = event.offsetY; }; var elem = document.getElementById("container"); elem.addEventListener("mousemove", onMousemove, false); This works

Horizontal scroll on mouseMove - wide div in smaller div with overflow:hidden (Can't get the math to work)

牧云@^-^@ 提交于 2019-12-03 03:58:33
问题 I'm trying to make a "line" of image thumbs, where it scrolls on mousemove. And I got it to work, but my problem now is that i wanted to make a "padding" on the sides so I doesn't have to have the mouse all the way out to the sides to see the first/last thumb. But I really really can't get it to work :/ This is the script I have now: // MouseMove scrolling on thumbs var box = $('.thumbs-block'), innerBox = $('.thumbs'), lastElement = innerBox.find('a:last-child'); var offsetPx = 100; var

jQuery: Fire mousemove events less often

徘徊边缘 提交于 2019-12-03 03:21:00
I'm trying to figure out a clean way to aggregate mousemove events so that I ensure my code gets called, but only once every 250-300 milliseconds. I've thought about using something like the following, but was wondering if there was a better pattern, or something jQuery provides that will do the same thing: var mousemove_timeout = null; $('body').mousemove(function() { if (mousemove_timeout == null) { mousemove_timeout = window.setTimeout(myFunction, 250); } }); function myFunction() { /* * Run my code... */ mousemove_timeout = null; } EDIT: The accepted answer below would work perfectly for

How to set pageX for simulated javascript event

穿精又带淫゛_ 提交于 2019-12-02 21:26:27
问题 I'm simulating a mousemove event on a DOM node by: var e = document.createEvent('MouseEvents'); e.initEvent('mousemove', true, true) node.dispatchEvent(e) However in my mousemove callback which is bound on the document, the event object is returned with a pageX of 0. Is there a way I can set pageX when initializing or dispatching the event? 回答1: From here: To see it working, just run this: document.addEventListener('mousemove', function (e) { console.log(e.pageX); }); var e = document

VBA - getting name of the label in mousemove event

这一生的挚爱 提交于 2019-12-02 18:02:36
问题 I have following problem. I have a lot of labels in my worksheet named in a structured way (Label1, Label2, ..., Label9) and mousemove-event macros assigned to all of them. I want to get ith value in table A1:A9, where "i" is a number of label, which is currently "touched". Is there a simple way to get label's name during mouse_move event (or some other events like Change_event). It would be look simmilar to this Private Sub Label47_MouseMove(ByVal Button As Integer, ByVal Shift As Integer,

Horizontal scroll on mouseMove - wide div in smaller div with overflow:hidden (Can't get the math to work)

江枫思渺然 提交于 2019-12-02 17:21:05
I'm trying to make a "line" of image thumbs, where it scrolls on mousemove. And I got it to work, but my problem now is that i wanted to make a "padding" on the sides so I doesn't have to have the mouse all the way out to the sides to see the first/last thumb. But I really really can't get it to work :/ This is the script I have now: // MouseMove scrolling on thumbs var box = $('.thumbs-block'), innerBox = $('.thumbs'), lastElement = innerBox.find('a:last-child'); var offsetPx = 100; var boxOffset = box.offset().left; var boxWidth = box.width() /* - (offsetPx*2)*/; var innerBoxWidth =

jQuery mousemove workaround

怎甘沉沦 提交于 2019-12-02 13:58:44
问题 I'm looking for a workaround for .mousemove() method on Chrome. It's a known issue. Chrome keeps firing mousemove repeatedly even if the mouse is still. I can't use .hover() method because the area is the window's height and width... I think about checking the mouse cursor coordinates and check if they changed, but I really don't know where to start. I reported to Chromium project: http://code.google.com/p/chromium/issues/detail?id=170631 回答1: Still got the Problem in Chrome Version 29.0.1547

How to prevent ggplot hoverOpts messages to go off screen with css

只愿长相守 提交于 2019-12-02 11:07:56
When running the demo App below, the problem I run into is that hover messages for the bottom part of the plot end up running off the screen. Does anybody know if there is a way to adjust the position so that the entire message always falls within the screen boundaries (l,r,t,b)? require('shiny') require('ggplot2') library(DT) ui <- pageWithSidebar( headerPanel("Hover off the page"), sidebarPanel(width = 2 ), mainPanel( tags$head( tags$style(' #my_tooltip { position: absolute; pointer-events:none; z-index: 1; padding: 0; }'), tags$script(' $(document).ready(function() { setTimeout(function(){

Move a window by clicking an internal widget instead of title bar

允我心安 提交于 2019-12-02 07:41:28
In Windows when I create a QMainWindow I can move it around the screen by clicking the title bar and dragging it. In my application I've hidden the title bar by using setWindowFlags(Qt::CustomizeWindowHint) and I'm trying to build a custom title bar using a widget and setting it in the menu space with setMenuWidget(myWidget) . Now I want to reproduce the original behaviour: I want to click on my MyWidget widget inside the QMainWindow and, while mouse is pressed, dragging the mouse moves the window. Is there a way to do it? This is an example on how to implement a fake title bar, that has

pointer motion. why are numbers so high? why does it print info in blocks not a constant stream?

馋奶兔 提交于 2019-12-02 06:11:45
Hi! I am trying to write a program where I need to report the position of every mouse motion. I have called the XSelectInput() function with a PointerMotionMask mask. Everything seems to work alright but the numbers after printing don't appear after every movement, they appear in blocks and also the numbers in event.xmotion.x and event.xmotion.y are very high, in the hundred thousands. What is causing these large numbers? Also is my program getting every number and reporting it immediately or is it being stored in a queue and sent in blocks to the terminal? Thanks Here's my event loop: while(1