我在 profile.php 中有一个可用的 slideDown div。当我单击用户名时,个人资料信息会向下滑动。这是结构,
profile.php - 这工作正常。
$('.showprofile').click(function() {
$('#userprofile').slideDown(1000);
});
我卡住的地方是,
我想在 users.php 上有一个链接
<a href='profile.php#userprofile'>
当我点击上面的链接时,我应该被带到 profile.php 页面,然后 userprofile div 应该自动向下滑动。
我怎样才能做到这一点?
最佳答案
只需将该代码添加到该页面的 $(window).load()
中,
<script>
$(document).ready(function(){
$(window).load(function(){
$('#userprofile').slideDown(1000);
});
});
</script>
注意,你应该在document.ready()
中注册window.load()
,因为可能有id为#userprofile的元素
页面加载后将不可用。
关于javascript - 从其他页面调用 slideDown(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20698018/