dom-events

Pass multiple arguments along with an event object to an event handler

人走茶凉 提交于 2019-12-03 10:12:20
问题 How can one pass multiple arguments along with an event object to an event handler without using Function.prototype.bind ? The event handler has a closure in it. The below basic code won't work, element.addEventListener("click", eventHandler(eventObj + arguments), false); function eventHandler(eventObj + arguments) { return function(){}; //a closure } I don't know how to pass event object and other arguments at the same time to an event handler. Updated: I have even tried using anonymous

Add onClick event to a group element (svg) with react

假装没事ソ 提交于 2019-12-03 10:08:21
I'm trying to add an onClick event to an existing svg. Right now I have this : <g id="Group" onClick={this.clickGroup.bind(this, 1)}> Which somewhat works but not entirely... The event fires when I click the group but the "zone" that is clickable isn't the same as the group I want to be clickable (it seems completely random to me). Is there any better way to add events to a <g> element (with React ?) ? A g element is just an empty container; it can not fire events by itself. If you run this example , you'll see that you can trigger the click event by clicking on the children of the g element,

Click Loads multiple videos using YOUTUBE Iframe

纵然是瞬间 提交于 2019-12-03 09:09:42
I have some thumbnails below the main video container. I will like when you click on each thumbnail - the associated video loads and start playing Using the NEW YOUTUBE API IFRAME approach here Your help or direction will be appreciated PREVIEW ON JSFIDDLE HERE PREVIEW LINK UPDATED*** Rob W See this fiddle: http://jsfiddle.net/Y9j7R/5/ Run this code on load: var a = document.getElementsByTagName("a"); //1 for(var i=0; i<a.length; i++){ //2 if(!/#ytplayer/.test(a[i].href)) continue; //3 var link = a[i].innerHTML.match(/\/vi\/([^\/]+)/); //4 if(link) (function(vidId){ //5 a[i].onclick = function

How can I tell when the browser stops repainting DOM layers/nodes because they are obscured?

荒凉一梦 提交于 2019-12-03 08:02:12
Identification: I'm looking at all possible solutions for detecting when the FPS drop or the repaints/reflows stop happening in a browser due to the browser optimizing performance because an area of the document is out of view. Observation: So far most native HTML/JS solutions I have researched do not take into account the portion of the DOM, which has been obscured by other pieces of the page, or DOM which is below the fold. While sometimes content will be directly embedded in the parent document, other times it may be in a frame or iframe. Test results: mozPaintCount is an accurate

How to make a click or double click on a word on a web page to trigger an event handler?

佐手、 提交于 2019-12-03 07:32:18
问题 For a page like http://www.answers.com if the user double clicks on any word in the page, a pop up box will show up and shows the definition for that word. I can think of a way to use DOM scripting to break up all words in the page and then make each of them go under a separate "span" element... but otherwise isn't it true that if all the text is under a "p" element, then the "p" element node get triggered to handle the double click event, but there is no easy way of telling which word is

JavaScript key handling and browser compatibility

依然范特西╮ 提交于 2019-12-03 07:17:48
I'm working on key handling in Javascript. I have done some research and I'd like to know whether I have a correct understanding of key handling. KeyDown/KeyUp Event The key down and key up events are supported by IE7+ and Firefox 3.5+ I didn't check the earlier versions of the browsers, but I guess that they also support these events. Is it correct to say that each key on the keyboard will always have a keycode. CharCode CharCode value is available on the keypress.Majority of the keys will have the charcodes that represent the actual value. Some keys won't have a charcode associated with them

`pointermove` event not working with touch. Why not?

久未见 提交于 2019-12-03 07:01:26
I have this pen: https://codepen.io/anon/pen/eyKeqK If you try it on a touch-screen device (f.e. visit the pen on your phone) you'll notice that when you drag, the white light (the little sphere) only moves for a tiny bit then it stops working. The logic for the movement is in the pointermove event handler. It works fine on Desktop using a mouse, just not with touch. How do we fix this so the light keeps moving while touch dragging (not just for a moment), and as bonus how do we prevent it from refreshing the page when we pull down? Here's the code for the pen: HTML (Slim): /! Made with http:/

Get horizontal scroll event in js

拜拜、爱过 提交于 2019-12-03 05:51:42
What I want to do, is to catch the event when the user is scrolling div horizontally. For vertical scroll I am using event 'mousewheel' and it's working properly. ( horizontal scroll is performed by a two finger drag on the touchpad - I am testing on Mac OS). You can handle horizontal scrolling by : $("#someContainer").on("scroll", function (e) { horizontal = e.currentTarget.scrollLeft; vertical = e.currentTarget.scrollTop; }); In this case this bind all kind of scroll events on this element so you can also handle Vertical by e.currentTarget.scrollTop and Horizontal by e.currentTarget

Cross-browser: detect blur event on window

萝らか妹 提交于 2019-12-03 05:47:12
I just read, I think all the thread that deals with this subject, and I can't find a real solution to my problem. I need to detect when the browser window loses its focus, i.e. a blur event. I've tried all the scripts on stackoverflow, but there doesn't seem to be a proper cross-browser approach. Firefox is the problematic browser here. A common approach using jQuery is: window.onblur = function() { console.log('blur'); } //Or the jQuery equivalent: jQuery(window).blur(function(){ console.log('blur'); }); This works in Chrome, IE and Opera, but Firefox doesn't detect the event. Is there a

Adding an onclick event to a div element

若如初见. 提交于 2019-12-03 04:46:00
问题 I saw a few similar topics which did help but I have specific problem and didn't manage to solve it alone so if anyone can help out I would appreciate it I want to add onclick event to a div element. HTML: <div id="thumb0" class="thumbs" onclick="klikaj('rad1')"></div> JavaScript: function klikaj(i) { document.getElementById(i).style.visibility='visible'; } Wanted result: div with id="rad1" (which is hidden) turns visible, when clicked on div with id="thumb0" . This works when I add it to a