10 examples of 'jquery addeventlistener' in JavaScript

Every line of 'jquery addeventlistener' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
31function addEventListener(element, event, handler) {
32 if (element.addEventListener) {
33 return element.addEventListener(event, handler, false);
34 }
35 if (element.attachEvent) {
36 return element.attachEvent('on' + event, function () { handler.call(element); });
37 }
38}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

9function addEventListener (element, event, funcs, opt) {
10
11 function fn (e) {
12 let data;
13 let target = e.target || e.srcElement;
14 e = e || window.e;
15
16 if (e.type === SCROLL) {
17 if (target === document) {
18 data = { scrollTop: document.body.scrollTop, scrollLeft: document.body.scrollLeft }
19 } else {
20 data = { scrollTop: target.scrollTop, scrollLeft: target.scrollLeft }
21 }
22 }
23
24 funcs.forEach(function (f) {
25 f(e, data);
26 })
27 }
28
29 if (_.isObject(opt)) {
30 if (_.isInteger(opt.throttle) && _.isFinite(opt.throttle) && opt.throttle > -1) {
31 console.log('Set throttle as ' + opt.throttle);
32 fn = _.throttle(fn, opt.throttle);
33 }
34
35 if (_.isInteger(opt.debounce) && _.isFinite(opt.debounce) && opt.debounce > -1) {
36 console.log('Set debounce as ' + opt.debounce);
37 fn = _.debounce(fn, opt.debounce);
38 }
39 }
40
41 // https://github.com/wangpin34/vue-scroll/issues/1
42 if (event === SCROLL) {
43 if(element === document.body || element === document || element === window) {
44 document.onscroll = fn;
45 } else {
46 if (element.addEventListener) {
47 element.addEventListener(event, fn);
48 } else {
49 element.attachEvent('on' + event, fn);
50 }
51 }
52 }
53
54}
48addEventListener(eventName: string, listener: () => void) {
49 // this.emitter.addListener(eventName, listener);
50}
313function addEventListener(el, eventName, callback, isUseCapture) {
314 if (el.addEventListener) {
315 el.addEventListener(eventName, callback, !!isUseCapture);
316 } else {
317 el.attachEvent('on' + eventName, callback);
318 }
319}
188function addListener(element, type, callback) {
189 if (element.addEventListener) element.addEventListener(type, callback);
190 else if (element.attachEvent) element.attachEvent('on' + type, callback);
191}
339addEventListener: function addEventListener (evt, handler) {
340 this._rootWidget.addEventListener(evt, handler);
341},
170var addEventListener = function addEventListener(element, eventName, callBack) {
171 var useCapture = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
172
173 element.addEventListener(eventName, callBack, useCapture);
174};
142public _addEventListener(type:string, listener:Function, useCapture:boolean = false):void {
143 if (type == "ended") {
144 this._onEndedCall = listener;
145 return;
146 }
147
148 this._listeners.push({type: type, listener: listener, useCapture: useCapture});
149 if (this._audio) {
150 this._audio.addEventListener(type, listener, useCapture);
151 }
152}
56function addEvent (el, name, fn) {
57 if (el.addEventListener) {
58 return el.addEventListener(name, fn, false)
59 } else if (el.attachEvent) {
60 return el.attachEvent('on' + name, fn)
61 }
62}
8export function addEvent(target, eventType, callback) {
9 if (target.addEventListener) {
10 target.addEventListener(eventType, callback, false);
11 return {
12 remove() {
13 target.removeEventListener(eventType, callback, false);
14 }
15 };
16 } else if (target.attachEvent) {
17 target.attachEvent(`on${eventType}`, callback);
18 return {
19 remove() {
20 target.detachEvent(`on${eventType}`, callback);
21 }
22 };
23 }
24 return null;
25}

Related snippets