Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set the offset in javascript

How can set the offset using JavaScript ?

like image 637
Santhosh Avatar asked Dec 23 '09 07:12

Santhosh


People also ask

What is offset in Javascript?

The offset() method set or returns the offset coordinates for the selected elements, relative to the document. When used to return the offset: This method returns the offset coordinates of the FIRST matched element. It returns an object with 2 properties; the top and left positions in pixels.

What is offset left in Javascript?

The offsetLeft property returns the left position (in pixels) relative to the parent. The returned value includes: the left position, and margin of the element. the left padding, scrollbar and border of the parent.

What is Canvas offset in Javascript?

Returns the number of pixels that the upper left corner of the current element is offset to the left within the offsetParent node.


1 Answers

You set the left and top CSS values.

With jQuery

$("#myEl").css({"position":"absolute","left":"100px","top":"100px"});

Vanilla JavaScript

var myEl = document.getElementById("myEl);
myEl.style.position = "absolute";
myEl.style.left = "100px";
myEl.style.top = "100px";
like image 75
Sampson Avatar answered Sep 25 '22 11:09

Sampson