Skip to content

Instantly share code, notes, and snippets.

@zgr024
Created April 5, 2012 15:33
Show Gist options
  • Save zgr024/2311989 to your computer and use it in GitHub Desktop.
Save zgr024/2311989 to your computer and use it in GitHub Desktop.
Scrolls to the element of your choice based on the id of the element and the $_GET[] parameter
<?
// PHP
if ($_GET['elementId']) {
?>
<input type="hidden" id="elementId" value="<?=$_GET['elementId']?>" />
<?
}
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
if ($('#elementId').val()) {
if ( $('#'+$('#elementId').val()).html() ) {
var idPos = $('#'+$('#elementId').val()).position().top;
$(window).scrollTop(idPos);
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment