dom-events

catch-all keyup/keydown events in iframe?

三世轮回 提交于 2019-12-01 00:53:15
问题 I'm working on a canvas-based game and am using window.addEventListener() to attach keyup and keydown events globally. This works in when viewing the page normally, but when embedding it as an iframe; it doesn't get the keyup and keydown events. Is there a better way I can do this? 回答1: You can't, not unless the frame has focus. What you can do is make a keydown on the outer window focus the iframe, or always somehow focus the iframe, or focus the iframe by default (might be good enough, not

Detect if element has stopped momentum scrolling?

久未见 提交于 2019-12-01 00:45:20
问题 Is it possibile to detect if an element has stopped scrolling in Mobile Safari via Javascript? I have an element that has momentum scrolling by using -webkit-overflow-scrolling:touch , and I need to detect if the element has stopped scrolling, including after the momentum affects the scroll. Is this possible? Using the onscroll event is not working as it should within my app. 回答1: You can calculate a swipe velocity and try to figure out if momentum scroll will occur based on some threshold

Capturing onkeydown in Javascript

可紊 提交于 2019-12-01 00:29:49
I have a web front-end to an AS/400 CGI application which allows the use of some of the F1 - F24 keys (depending on the page) as well as page-up, page-down etc - these are passed to the underlying application which handles them appropriately. For instance, on a given page, a user could either press the F3 button or press the F3 key - both of them will set the (hidden) CmdKey variable to have a name of '_K03' and a value of 'F03'. The button handling is simple and has no problems. To handle users pressing an actual F-key on the keyboard, I have had an IE-compatible script for a long time which

Event for browser tab hidden/shown?

江枫思渺然 提交于 2019-11-30 22:54:55
Is there any DOM event for when the browser tab loses/gains focus? I know there are the blur and focus events on window , but they also fire when the browser window as a whole loses focus. The browser might then be still visible to the user. Of course such an event would be browser specific, but that's ok. The reason why I want this is because I run animations that might consume quite some CPU time. When the browser tab is not visible there is no reason to continue animating. Now I know that modern browsers reduce the timer resolution of background tabs, but I could actually pause the

How to disable default Help function of browsers

眉间皱痕 提交于 2019-11-30 22:51:23
I want to disable or override the default help function of browsers. I tried to look at few examples online but they are not working for me. (The following code is working on Firefox and Chrome but not on Opera and IE) <html> <title> </title> <body> <script src = "jquery-1.7.1.min.js" text="type="text/javascript""></script> <script language="javascript" type="text/javascript"> document.onkeydown = function(event) { if(window.event && window.event.keyCode == 112) { event.stopPropagation(); event.preventDefault(); event.keyCode = 0; return false; //document.onhelp = new Function("return false;")

Difference between Events and Functions?

对着背影说爱祢 提交于 2019-11-30 20:58:00
I am new to Node, and I am struggling to understand the main difference between Events and Functions. Both need to be triggered, so why do we need an Event at all if we have to trigger it anyway? How is it different than having a Function triggered? Example code: var events = require('events'); var eventEmitter = new events.EventEmitter(); eventEmitter.on('event1', function () { console.log('Event 1 executed.'); eventEmitter.emit('event2'); }); eventEmitter.on('event2', function() { console.log('Event 2 executed.'); }); eventEmitter.emit('event1'); console.log('Program Ended.'); We can achieve

How to change the value of a check box onClick using JQuery?

我是研究僧i 提交于 2019-11-30 20:09:26
Here I am trying to change the value of the following check box while clicking on it. In the code below I tried to change the value of the checkbox to 1 and change the value to 0 when unchecked. But it takes only the false condition, when the checkbox is unchecked the value changes to 0 but when checked its not changing to 1. Any suggestions how to fix this out ? <input type="checkbox" id="read" name="permission[]" onClick="($(this).checked)?$(this).attr('value',1):$(this).attr('value',0)"/> I don't really understand why you would want to do this (the checkbox's value won't be submitted

Event for browser tab hidden/shown?

本秂侑毒 提交于 2019-11-30 17:46:20
问题 Is there any DOM event for when the browser tab loses/gains focus? I know there are the blur and focus events on window , but they also fire when the browser window as a whole loses focus. The browser might then be still visible to the user. Of course such an event would be browser specific, but that's ok. The reason why I want this is because I run animations that might consume quite some CPU time. When the browser tab is not visible there is no reason to continue animating. Now I know that

How to use Twitter Bootstrap ScrollSpy to execute a function

余生长醉 提交于 2019-11-30 17:44:33
问题 I would like to load more data after ScrollSpy receives notification. But I don't see how to capture that event and execute a function. 回答1: UPDATED This trigger has been pushed into the main build now. You can see it in full docs. http://twitter.github.com/bootstrap/javascript.html#scrollspy There is an update in the working branch on github that fires an activate callback. References https://github.com/twitter/bootstrap/issues/2482 Once you grab the activate trigger, you can call it like so

How to disable default Help function of browsers

[亡魂溺海] 提交于 2019-11-30 17:33:49
问题 I want to disable or override the default help function of browsers. I tried to look at few examples online but they are not working for me. (The following code is working on Firefox and Chrome but not on Opera and IE) <html> <title> </title> <body> <script src = "jquery-1.7.1.min.js" text="type="text/javascript""></script> <script language="javascript" type="text/javascript"> document.onkeydown = function(event) { if(window.event && window.event.keyCode == 112) { event.stopPropagation();