Position of Div in relation to the Top of the Viewport

The existing answers are now outdated. The getBoundingClientRect() method has been around for quite a while now, and does exactly what this question asks for. Plus it is supported across all browsers. From this MDN page: The returned value is a TextRectangle object, which contains read-only left, top, right and bottom properties describing the border-box, …

Read more

What are pixels and points in iOS?

A pixel on iOS is the full resolution of the device, which means if I have an image that is 100×100 pixels in length, then the phone will render it 100×100 pixels on a standard non-retina device. However, because newer iPhones have a quadrupled pixel density, that same image will render at 100×100 pixels, but …

Read more

How to read the Color of a Screen Pixel

This is the most efficient: It grabs a pixel at the location of the cursor, and doesn’t rely on only having one monitor. using System; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Diagnostics; namespace FormTest { public partial class Form1 : Form { [DllImport(“user32.dll”)] static extern bool GetCursorPos(ref Point lpPoint); [DllImport(“gdi32.dll”, CharSet = …

Read more

Android TextView setTextSize incorrectly increases text size [duplicate]

Heh, mixed units problem. Seems a little counterintuitive, but it’s an easy fix. The default method setTextSize(float) assumes you’re inputting sp units (scaled pixels), while the getTextSize() method returns an exact pixel size. You can fix this by using the alternate setTextSize(TypedValue, float), like so: this.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); This will make sure you’re working with the …

Read more