javascript-events

why are onkeyup events not firing in javascript game

时间秒杀一切 提交于 2019-12-12 13:36:16
问题 I have the beginnings of a 2d javascript game - at the moment the player can drive a triangle around the screen using the arrow keys. The problem is that sometimes the triangle will get stuck rotating in one direction or moving forward until the corresponding control key is pressed again and the onkeyup event is fired again. This usually happens when more than one control key is pressed at the same time. I can't work out why it's getting stuck in the first place unless the onkeyup events aren

How to Create a TouchEvent in Chrome?

陌路散爱 提交于 2019-12-12 13:33:26
问题 The W3C specification declares initTouchEvent as following: void initTouchEvent (in DOMString type, in boolean canBubble, in boolean cancelable, in AbstractView view, in long detail, in boolean ctrlKey, in boolean altKey, in boolean shiftKey, in boolean metaKey, in TouchList touches, in TouchList targetTouches, in TouchList changedTouches); However, when I try it in Chrome 44: var e = document.createEvent('TouchEvent'); e.initTouchEvent("touchstart", true, true, window, 1, false, false, false

HTML page submission without redirection

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 12:26:20
问题 Is there any method to submit an html form without redirecting from the current page without using ajax ? 回答1: you can set a target="" for your form - so you could submit your form to a new tab ( target="_blank" ) or to a small, hidden iframe ( target="nameofmyiframe" ) 回答2: Without using ajax? An iframe. Is it recommended? No. Why can't you use ajax techniques? 回答3: Use any element that relies on external resources. If file uploading is required Change the target attribute of the form to the

Triggering click event with modifier keys on input element

拜拜、爱过 提交于 2019-12-12 12:25:57
问题 I'm writing a test for some functionality that involves user shift-clicking on a checkbox. I'm using $('input').trigger($.Event('click', { shiftKey: true })); to simulate that. But when the event listener gets called, event.shiftKey property always gets reported as false when originating from my synthetic events, while real clicks produce the desired effect. What's more confusing, triggering the same event on a non- input element seems to work just fine. See http://jsfiddle.net/huskssk1/ for

Are directly assigned event handlers actual object properties?

て烟熏妆下的殇ゞ 提交于 2019-12-12 12:04:00
问题 I got stuck trying to answer this question: Explaining odd behavior in javascript. While researching, I found that event handlers assigned directly to host objects present a strange behavior: they can be accessed as properties of the object, but somehow they don't appear to be actual properties. For example, if I define a variable on the global scope, it looks like any other property of window : ​var foo = "foo"; console.log(Object.getOwnPropertyDescriptor(window, 'foo')); // Object {value:

javascript resize event not working

只谈情不闲聊 提交于 2019-12-12 11:18:33
问题 I don't know why this doesn't work: window.addEventListener('load', setSize(), false); window.addEventListener('resize', setSize(), false); function setSize(){ width = window.innerWidth; console.log(width); } It logs the width right after load, but it doesn't do that when I resize. 回答1: window.addEventListener('load', setSize(), false); window.addEventListener('resize', setSize(), false); should be: window.addEventListener('load', setSize, false); window.addEventListener('resize', setSize,

Javascript: IE8 event coordinates

无人久伴 提交于 2019-12-12 11:15:36
问题 I can't seem to find a way to get coordinates of event in IE8, it just triggers errors like... pageX undefined, clientX undefined etc. While it works find in other browsers. This is what I was trying to do: document.onmousemove=setcoord; function setcoord(e){ var xxcoord = e.pageX||(e.clientX+document.body.scrollLeft); var yycoord = e.pageY||(e.clientY+document.body.scrollTop); } Is there any workaround to get that mouse position ?.. 回答1: The following seems to work. I'm not sure its is the

Mobile Safari Event Issue

假如想象 提交于 2019-12-12 10:39:44
问题 I have designed a website with a menu that is initially invisible. When the user clicks on a button, the menu becomes visible. There are two ways for the user to hide the now visible menu: Click the button that caused the menu to become visible Click anywhere on the webpage that isn't the menu The way I have coded the second option is to tie an onclick event to the window element, and have it compare where the user clicked to the menu's position to determine if the menu should be hidden. This

how to add an eventListener to an Object in javascript which will fire when object is manipulated?

老子叫甜甜 提交于 2019-12-12 10:37:12
问题 I have a complicated UI structure which is manipulated dynamically, and say I have an ui_state object where i keep user's latest UI states such as which tab was visible, what was inside that tab etc. For instance: var ui_states = { tabs : [ { name : "some tab", active : true, children : { ... } }, { name : "some other tab", children : { ... } } ] } I keep this on html5 localStorage and when user refreshes the site it reopens the page the same. And everytime when the UI changes this object is

Prevent form from submitting

允我心安 提交于 2019-12-12 10:22:32
问题 I have this $("#contact-frm-2").bind("jqv.form.result", function(event , errorFound){ if(!errorFound){ alert('go!'); event.preventDefault(); return false; } }); It supposed to validate the form for errors and when there is no error on the form, alert "Go!" without submitting. I am using the jquery.ValidationEngine.js you can find at http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ I am sure event.preventDefault(); return false; is supposed to