简体   繁体   English

页面加载时,PHP jQuery转到div

[英]PHP jQuery go to div when page is loaded

The other day i saw this jsfiddle: http://jsfiddle.net/lollero/ZVdRt/ 前几天,我看到了这个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. 当直接以标题中的param开头时,它也应该在页面底部打印jquery,并且在加载页面时运行该代码,并以id为id转到div。

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 }?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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