简体   繁体   中英

PHP jQuery go to div when page is loaded

The other day i saw this jsfiddle: http://jsfiddle.net/lollero/ZVdRt/

I would like to implement this function on my page with the following condition:

<?php if(isset($_POST['scrolltodiv']){ $goto = "#pliip";} ?>

when the direct starts with the param in header it should also print the jquery in the bottom of the page and when page is loaded run that code and go to the div with the param as id.

Any idea how to make this functional?

You can try this :

<?php if(isset($_POST['scrolltodiv']){?>
<script type="text/javascript">
       $(document).ready(function() {
                $("html, body").animate({ scrollTop: $("#pliip").offset().top}, 1000);
       });
</script>
<?php }?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM