Is it possible to add an anchor to this script? Instead of scrolling all the way to the top, I would like to scroll to a particular anchor in the page.
Here is the current script:
if (isError) {
$('html, body').animate({
scrollTop: 700
}, 2500);
$("#error-div").show();
} else {
$("#error-div").hide();
}
There’s not really the need to include a huge plugin for this simple task.
With jQuerys
position()– function (jQuery Doc) you can get the position of an element in the DOM (as long as it’s visible). It returns an object with atopandleft– value, relative to the parent. If you want values relative to the document, use theoffset()– function, usage stays the same.I created a little fiddle to show you the basic usage:
http://jsfiddle.net/DtADS/