The King is The King is - 4 months ago 9
jQuery Question

Setting a height range between the window top and an element using jQuery

I have an

url
like this
website.com/#site
so that when I load the page the
div name="site"
is highlighted but my problem is that the
div
stays at the very top of the window which causes some obstruction so is there a way with I can push down the
div
element by setting a margin between it and the window top for example

$(document).ready(function (){
//set margin between window.height() and div element;
})


I would also appreciate other methods apart from
jQuery

Answer

You can achieve your aim like this

// the margin can be set to any desired value
margin = 200;
$('html, body').animate({
    scrollTop:$('div').offset().top - margin
}, 2000);