Find x and y position of an element using JavaScript
1 of November2007
Ever needed to find the x or y coordinates of an element on a page? Well, thanks to this script from quirksmode it’s possible.
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}
var elemToFind = document.getElementById('div1');
var elemCoords = findPos(elemToFind);
So now, elemCoords holds both the x and the y. Since findPos() returns an array, to access the x or y by itself do the following:
// elemCoords[0] or elemCoords[1] for the x and y values, respectively alert(elemCoords[0]);
Tags: Coding, JavaScript
Posted in JavaScript
How to write a CSS rule that will affect every element:
25 of October2007
Sometimes there’s a need to reset all of the margins on a page, or you simply want something specifically applied to each element without having to count on inheritances to do the job. The solution: “*” or “universal selector”. This seems familiar from other languages right? Well, it should be. It simply means “everything” in a selected area.
The following will apply a gray background to every element on a page.
* {
background-color: #eee;
}
What if you want to get more specific?
With this code, everything within the div with the id=”wrapper” will have a gray background.
div#wrapper * {
background-color: #eee;
}
Obviously any properties can be used here. Enjoy.
Give me a voice.
17 of October2007
My newest pet peeve: Blogs that don’t allow you to comment.
It’s human nature to need interaction in a time of ever decreasing social abilities.
I enjoy reading blogs. I enjoy reading the comments that go back and forth. I enjoy reading about Design and other teachnical stuff.
Two blogs I have started reading regularly have sparked this: Northtemple and I hereby Decree.
Both are very much worth my time. Oftentimes I have questions. I don’t understand what’s being referred to. Or, I feel strongly on the subject. Let me talk to you. Let me give my opinion. Let me interact with you. Let me be human. So please, give me a voice. Allow commenting, and I promise, I will comment.
Tags: Blog
Posted in Uncategorized
People who say “it can’t be done” are usually dead-wrong
15 of October2007
As as UI designer I am in a field where I am constantly trying to find new solution to existing problems. These are problems that other people either don’t even think about fixing, or they think it’s too hard, so they don’t bother.
Frequently when I ask somebody if Task A “can be done”, I get the typical ” No, that can’t be done.” or “I would require a LOT of work”. Well, here’s my declaration to the world:” People who say it can’t be done are usually dead wrong“.
I can’t even count the times an “expert” has told me something can’t be done, and (oftentimes) with just a little research I figured a way to do, what “couldn’t be done”. So here’s to you. Don’t take no for an answer. Ask why it can’t be done, and then try to solve that hindrance. You will have amazing results.
Please, leave me a comment and tell me how you feel about this.
Posted in Uncategorized
WordPress Update
12 of October2007
I just updated my WordPress version. Some of my “custom” styles went whacky. I apologize if the blog doesn’t look like it should. I will fix it later today or tomorrow have now fixed it. Everything should be back to normal
Posted in Uncategorized