내 질문은 완전히 같은 것입니다 : How do I pass javascript events from one element to another? 사실 나는 raw JS 솔루션이 필요하다는 것을 제외하고는.하나의 dom 노드에서 다른 노드로 이벤트 라우팅하기
UI가 페이지의 각 요소와 함께 스크롤되는 요소가있는 webos 앱이 있습니다. 기본적으로 iframe의 양은 얼마입니까 (원칙적으로는 아니지만). z 레이어 위에있는 유동 헤더가 있습니다. iframe의 요소를 스크롤하면 떠 다니는 머리글도 위로 이동합니다.
그러나 헤더를 끌 때 원본 문서를 스크롤해야합니다.
이것은 터치 스크린 인터페이스이므로 onmousemove 및 ontouchmove 이벤트를 시도하고 있습니다.
나는 다음과 같은 코드를 가지고,하지만 아무것도 할 것 같지 않습니다 당
setupScrollFromHeader: function setupScrollFromHeader() {
// webos enyo stuff. Don't worry about it. just know that I get the
// raw dom elements through the this.$.elem.node syntax
var body = this.$.body, header = this.$.mailHeaderUnit;
if (!header.hasNode() && !body.hasNode()) {
return;
}
body = body.node;
// end enyo specific stuff
header.node.addEventListener('touchmove', function(event) {
console.log("### touch move");
event.preventDefault();
body.dispatchEvent(event);
var touch = event.touches[0];
console.log("Touch x:" + touch.pageX + ", y:" + touch.pageY);
}, true);
console.log("### set this stuff up");
}
내가 이벤트를 전달하는 데에 dispatchEvent를 사용하고을 : https://developer.mozilla.org/en/DOM/element.dispatchEvent
내가했습니다 touchmove 및 mousemove 이벤트를 자체적으로 시도하고 기본값을 설정하지 않고 true/false 플래그로 버블 링 동작을 변경했습니다.
모든 경우에 로그가 인쇄되지만 이벤트는 기본 요소로 전달되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 이런 식으로 이벤트를 전달할 수 있습니까?
표시된 코드가 불완전합니다. ** 전체 ** (관련) 소스를 보여주십시오. (예 :'this. $. mailHeaderUnit','this. $','this. $. body') –
그것은 무의미합니다. 내가 필요한 노드가 있다는 것을 알아라. header.node는 플로팅 헤더의 원시 DOM 노드를 가져옵니다. Body.node는 내 몸체의 원시 노드를 가져옵니다. – Gopherkhan
[DOM 이벤트를 복제하거나 재 전달하는 방법]의 가능한 복제본 (https://stackoverflow.com/questions/11974262/how-to-clone-or-re-dispatch-dom-events) –