How to distinguish between blank areas and non-blank areas in a webpage with JavaScript? Blank areas including:
- areas that are not occupied by DOM elements.
- margins, borders and paddings of DOM elements.
EDIT:
As response to the first comment: I am working on a web-based ebook reader. Cursor is set to {cursor:move} for blank areas so that the user can drag and scroll the webpage.
You could recursively go through each element and attach
onmouseoverandonmouseoutevents (where the former enables thetextcursor and the latter enables themovecursor) on each which has text in it, e.g:The best way I can think of to make sure it’s actually “text” which is moused over and not a blank area is to use e.g.
<div><span>content</span></div>and put themouseover/mouseoutevents in the<span>so that blank areas don’t trigger events. This is what I’d recommend doing if you can, as things can get very complicated if you use block elements with padding from my experience. For example:If you have to use block DIVs: You could use something like jQuery’s
jSizesplugin to get margins/padding in pixels or this (for a way to get the inherited CSS values and parse yourself by removing thepxpart from the end etc)After that, you could figure out the position using
position()in jQuery. I personally don’t use jQuery for my stuff, but I use those specific “find positions” functions and found them to be one of the best I think in large part because of number of users testing them.Good luck!