Thursday, March 13th, 2008

W3C CSSOM View Module

Category: Browsers, JavaScript, Standards

PPK has blogged a critique of the new W3C CSSOM View Module. He is a fan:

W3C published the first working draft of the W3C CSSOM View specification (written by Anne van Kesteren), and I must say I’m very happy with it. Since I was testing stuff anyway I created a new compatibility table for most of the methods and properties specified in this document, and browser compatibility is already excellent.

What does this new module do? “The APIs introduced by this specification provide authors with a way to inspect and manipulate the view information of a document. This includes getting the position of element layout boxes, obtaining the width of the viewport through script, and also scrolling an element.”

PPK calls out one special method, elementFromPoint:

This method expects two coordinates and then reports which HTML element is located at these coordinates. This is a godsend for drag-and-drop scripts. If the user drops an element, get the mouse coordinates and use this method to find out which HTML element is located at these coordinates.

One catch: you first have to temporarily hide the dragged element, because otherwise elementFromPoint() would always report the dragged element — after all it itself is the topmost element under the mouse.

I’m going to add this functionality to my Drag and Drop script, but for the moment this seems to be the idea:

javascript

  1. releaseElement: function(e) { // called onmouseup
  2.     var evt = e || window.event;
  3.     dragDrop.draggedObject.style.display = 'none';
  4.     var receiver
  5.         = document.elementFromPoint(evt.clientX,evt.clientY);
  6.     dragDrop.draggedObject.style.display = '';

Posted by Dion Almaer at 6:05 am
1 Comment

+++--
3.6 rating from 11 votes

1 Comment »

Comments feed TrackBack URI

I recommend reading the editor’s draft instead http://dev.w3.org/csswg/cssom-view/ given that you like reading specifications in the first place :-) It contains some important updates.

Comment by Anne van Kesteren — March 13, 2008

Leave a comment

You must be logged in to post a comment.