How can set the offset using JavaScript ?
3 Answers
If the container is scrollable, the scroll method may be more in line with the specification. If not, it has to be solved by setting the absolute positioning
Element.scroll() - Web APIs | MDN
// Put the 1000th vertical pixel at the top of the element
element.scroll(0, 1000);
// use optionas
element.scroll({
top: 100,
left: 100,
behavior: 'smooth'
});
Comments
You could also add a class, e.g.
Jquery: $("p:last").addClass("selected");
Javascript: Someone has posted a JS function here - http://bytes.com/topic/javascript/answers/542128-can-javascript-add-new-style-class
You would then need to make sure that 'selected' was defined in your style sheet. The relevant CSS properties are:
top left margin padding
You probably want a combination of margin (offset outside element) and padding (offset inside element).