Created
April 5, 2012 15:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// 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