javascript - 从其他页面调用 slideDown()

标签 javascript jquery ajax

我在 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/

相关文章:

javascript - 如何用 jasmine 测试后调用?

javascript - 无法通过 CID 获取 Backbone 集合中的模型

javascript - 显示 Meteor 中的所有用户

python - 如何在简单的 wsgi 应用程序中响应 ajax?

javascript - 使用搜索建议

javascript - AngularJS - For 循环推送整个对象而不仅仅是标题

jquery - AngularJS ng-click 事件未从表中的 anchor 标记执行

jQuery滚动功能不断跳跃

javascript - 使用 highcharts 在堆栈标签中显示特定系列值

javascript - 使用 JavaScript 和 Jade 添加到 localStorage