javascript-events

JavaScript function parameter - Beginner Question

无人久伴 提交于 2019-12-24 11:36:49
问题 I am new to JavaScript and coming from Python. I am having a hard time to understand where the 'rect' is coming from and how it is passed in the following script (that I took from tracking.js): Any help would be really appreciated and I believe this question would probably also help any other coming from Python. <!doctype html> <html> <head> <meta charset="utf-8"> <title>tracking.js - first tracking</title> <script src="../build/tracking-min.js"></script> </head> <body> <video id="myVideo"

Difference between addEventListener and jquery on?

为君一笑 提交于 2019-12-24 11:33:59
问题 So I am trying to capture all the click events on a page. I can use this window.addEventListener('click', function(e){ console.log(e.target); }, true); or $("*").delegate("*", "click", function(e){ if (e.target === this) { console.log(e.target); } }); What is the difference? 回答1: There are a couple of differences actually: You can't use capture for jQuery .on(), such a thing just doesn't exist. jQuery only supports event bubbling. You could, however, specify whether to capture the event in

How can I determine start and stop points for mouse cursor?

半腔热情 提交于 2019-12-24 11:04:17
问题 Let's say the user starts to move mouse and stop at somewhere on the browser. How can I determine start and stop point with Javascript/Jquery ? Start point is easy, I can get it with mousemove event but what about stop point ? I can't use mouseenter or mouseleave events because my playground is window or document itself. Thank you. 回答1: using a combination of setTimeout and clearTimeout. If the user doesn't move for x amount of seconds then it means that he stopped. Here I wrote you an

Use submit event listener when form is submitted via inline JavaScript?

孤街浪徒 提交于 2019-12-24 10:53:41
问题 We have a script that tracks form submits by adding an event listener to the form. The problem is that one customer submits the form via a link using <a href="javascript:document.formname.submit();">Submit</a> which ignores the event listener. Here's a JSFiddle to demonstrate: http://jsfiddle.net/XhLkG/ As you can see the Submit button triggers the alert while the Submit link simply just submits the form and bypasses the event listener. Is there a way to still trigger the event listener? EDIT

Stop Event Propagation for a Specific Handler

◇◆丶佛笑我妖孽 提交于 2019-12-24 10:49:02
问题 tl;dr Summary Write a function that—when registered to handle a specific event on multiple elements in a hierarchy—executes on the first element reached during bubbling but does not execute (or returns early) when bubbling further up the hierarchy. (Without actually stopping propagation of the event.) Simple Example Given this HTML… <!DOCTYPE html> <body> <div><button>click</button></div> <script> var d = document.querySelector('div'), b = document.querySelector('button'); d.addEventListener(

Initiate a click event in a twitter chrome extension

ぃ、小莉子 提交于 2019-12-24 10:48:18
问题 I try to initiate a click event on Twitter's .com web page. But somehow it doesn't work when I try the code in my extension. if(typeof TIP == 'undefined'){ var TIP = {}; } TIP.Tweets = { getNumberOfTweets: function(){ var tweets = $('#stream-items-id .js-stream-item').length; return tweets; }, setNumberOfTweets: function(number){ TIP.Tweets.currentNumberOfTweets = number; } } TIP.initiate = function(){ TIP.Tweets.currentNumberOfTweet = TIP.Tweets.getNumberOfTweets(); setInterval(function(){

grab/copy/convert to variable: google translated text (write to other page) client side

人盡茶涼 提交于 2019-12-24 10:38:55
问题 Primarily need to understand how to manipulate the displayed translated text, using javascript, in order to convert it to usable text. I'm creating a 3 box translation system: source text-->translated text-->source language This will allow English to be entered. The French translation (next to it). The French translated back into English (next to it). This would be the ultimate google translator as the writer could check his French translation by reading it in English (as he types it!!);

KineticJS event not fired for child of a grouped layer

℡╲_俬逩灬. 提交于 2019-12-24 09:34:34
问题 I am trying to add a click event to an image ( Kinetic.Image ) I am adding to a KineticJS stage. When I use a simple hierarchy, as shown below (Test 0) the event can be successfully triggered. However when adding the image in a more complex hierarchy (Test 1) the event is not triggered. I have created a Fiddle that demonstrates both hierarchy situations. // The canvas container for the stage var container = $("#container").html(""); // Create the stage var stage = new Kinetic.Stage({

Looping result last index of array [duplicate]

一笑奈何 提交于 2019-12-24 09:14:42
问题 This question already has answers here : JavaScript closure inside loops – simple practical example (44 answers) Closed last year . I have the following code, to add each element an event using addeventlistener var x, y, z; elm = elm.normalize(); if(!isobj(elm) && iselm(elm)) { elm = new Array(elm); } for(x in elm) { (function() { elm[x].addEventListener('click', function() { alert(x); }); })(); } but when i click any element that added an event by the loop it always show the last index

Custom jQuery event

帅比萌擦擦* 提交于 2019-12-24 08:25:42
问题 I want to create my own event - OnPositionChange. Event implementation of course is not a problem. The point is, how to trigger it when top or left style has changed? Should I overwrite prototype of $.css() function, or is there a better solution? 回答1: I'm not sure about an ideal method, but you could always set an interval that tracks whether those css values have changed, and then trigger the event: //Usage same as bind $('#element').PositionChange(function(){...}); $.fn.PositionChange =