jQuery滚动到元素不起作用2 [英] jQuery scroll to element not working 2

查看:77
本文介绍了jQuery滚动到元素不起作用2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案中,我在<body>之后有以下内容:

From this answer, I have the following after my <body>:

<a name="Pagetop"></a>

在页脚中,我有:

<script>
    jQuery(".pgtop").click(function() {
        jQuery('html, body').animate({
            scrollTop: jQuery("#Pagetop").offset().top
        }, 2000);
    });
</script>
<p class="pgtop"><img src="<?php echo get_stylesheet_directory_uri() ?>/images/up-arrow.png" alt ="Go to top of page" title ="Go to top of page" width="50" height="29" border = "0" ></p>

,但滚动到顶部在此登台网站上不起作用.

帮助表示赞赏.

推荐答案

将页面顶部目标元素更改为使用id而不是name属性

Change your page-top target element to use id instead of name property

<a id="Pagetop"></a>

此外,在绑定元素之前,请等待页面加载.

Also, wait for your page to load before binding the element.

 jQuery(document).ready(function () {
    jQuery(".pgtop").click(function () {
        jQuery('html, body').animate({
            scrollTop: jQuery("#Pagetop").offset().top
        }, 2000);
    });
});

这篇关于jQuery滚动到元素不起作用2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆