简体   繁体   English

什么可能导致我的scrollTo功能出现问题?

[英]What could be causing an issue with my scrollTo function?

I have a button that resides at the bottom of my page that is supposed to scroll to the top of the page when clicked. 我有一个位于页面底部的按钮,该按钮应该在单击时滚动到页面顶部。

I used identical code from another site that I've worked on to implement this feature, but for some reason nothing happens within the current site with the scrollTop feature. 我使用了其他网站中相同的代码来实现此功能,但由于某些原因,当前站点中没有任何事情发生,使用了scrollTop功能。

I've tested the effect with another element on the page and it works if I set the 'button' as a different div, but when I revert it back to the div I want to be able to click from, again the feature no longer works. 我已经使用页面上的另一个元素测试了效果,如果我将“按钮”设置为不同的div,它可以正常工作,但是当我将其恢复为我希望能够点击的div时,再次不再使用该功能作品。

Here is my code if anyone might be able to tell what is wrong. 这是我的代码,如果有人可能能够分辨出什么是错的。

Here is a fiddle of the actual page http://jsfiddle.net/6p6MZ/4/ 这是实际页面http://jsfiddle.net/6p6MZ/4/的小提琴

What I have in my head tag: 我头上的标签:

<link rel="shortcut icon" href="images/favi.ico" />
<link href="css/about-3elements.css" rel="stylesheet">
<link href="css/pages.css" rel="stylesheet">
<link href="css/page-transitions.css" rel="stylesheet">
<link href="css/footer.css" rel="stylesheet">
<link href="css/responsive-mobile.css" rel="stylesheet">
<link href="css/responsive-tablet.css" rel="stylesheet">
<link href="css/responsive-1025-1500px.css" rel="stylesheet">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/modernizr.custom.28468.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>

Script: 脚本:

<script><!-----------------------------CONTROLS FOOTER BUTTON THAT GOES TO THE TOP OF THE PAGE----------------------------------->
$(document).ready(function(){
    $(this).scrollTop(0);
});

$("#nav-arrow").click(function() {
    $('html, body').animate({
        scrollTop: $("html").offset().top
    }, 750);
});
</script>
HTML:

<footer class="bottom-footer">
<div id="nav-arrow"><img src="images/nav-arrow.svg" width="35%"><br><span class="arrow-text" style="width:100px; color:#f8f4ec; font-family:myriad pro, arial, sans-serif; font-size:1.25em;">Back to top</span></div>

<section class="footer-section">
<ul>
    <li><a href="faq.html">FAQ</a></li>
    <li><a href="terms-of-use.html">TERMS</a></li>
    <li><a href="usage-rights.html">USAGE RIGHTS</a></li>
    <li><a href="privacy-policy.html">PRIVACY POLICY</a></li>
    <li><a href="contact.html">CONTACT</a></li>
    <li><a href="the-editors.html">MEET THE STAFF</a></li>
</ul>

<div id="social-links-container">
<ul class="social" style="height:40px;">
<li><a href="https://twitter.com/3ElementsReview" title="Follow @3ElementsReview" target="_blank"><img src="images/twitter.svg" width="25%" alt="If you like our literary journal, follow 3Elements Review on Twitter" border="none"></a></li>
<li><a href="https://www.facebook.com/pages/3Elements-Review/165239120323115" title="Like us on Facebook" target="_blank"><img src="images/facebook.svg" width="25%" alt="If you find our literary journal interesting, like 3Elements Review on Facebook" border="none"></a></li>
<li><a href="https://plus.google.com/102175306984563852786" rel="publisher" title="+1 our page on Google+" target="_blank"><img src="images/google-plus.svg" width="25%" alt="Recommend our literary journal 3Elements Review on Google+" border="none"></a></li>
<li><a href="http://www.stumbleupon.com/stumbler/3elementsreview" title="Come say hello!" target="_blank"><img src="images/stumble.svg" width="25%" alt="If you like our literary journal, you can find our 3Elements Review page on StumbleUpon" border="none"></a></li>
</ul>
</div><!---------------SOCIAL LINKS CONTAINER  END-------------------->

<h1 class="site-design">&nbsp;&nbsp;&nbsp;&copy;&nbsp;<script type="text/javascript">
    var dteNow = new Date();
    var intYear = dteNow.getFullYear();
    document.write(intYear);
</script> 3Elements Literary Review, Chicago, IL&nbsp;&nbsp;<a href="http://www.marlonfowler.com" target="_blank">Site design by Marlon Fowler</a></h1>

</section>
</footer>
</div><!------------------------CONTAINER THAT SURROUNDS ALL CONTENT BELOW THE NAVIGATION BAR  END------------------------------->

Live demo example 现场演示示例

Why not simply scrollTop to 0 ? 为什么不简单地scrollTop0

$("#nav-arrow").click(function() {
    $('html, body').animate({scrollTop: 0}, 750);
});

Any why in your code you have twice: 您的代码中有两次原因:

$(document).ready(function(){
    $(this).scrollTop(0);
});

?

Why you have 4 times document.ready at all? 为什么你有4次document.ready

Your example works, you just need to make sure jQuery is loaded. 您的示例有效,您只需要确保加载jQuery。 Here is your example with jquery loaded, done from the top left dropdown in jsfiddle. 这是你加载jquery的例子,从jsfiddle的左上角下拉列表完成。

http://bit.ly/1bJ8DXG http://bit.ly/1bJ8DXG

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

相关问题 jQuery scrollTo函数的问题 - Issue with jQuery scrollTo function 是什么导致我的阵列出现此问题...? - What is causing this issue with my array…? 什么可能导致这个奇怪的角度ui模式问题? - What could be causing this odd angular ui modal issue? 什么可能导致我的 canvas 游戏中的鼠标 position 出现这种偏移? - What could be causing this offset in the mouse position on my canvas game? 我的错误处理代码的哪一部分可能导致 Heroku 崩溃? - What part of my error handling code could be causing Heroku to crash? 哪些主题更改可能导致BigCommerce快速搜索不起作用? - What theme changes could be causing BigCommerce quick search to not function? 导致TypeError的原因是:使用gtoken和pify,期望`input`是一个`Function`或`Object`问题? - What is causing TypeError: Expected `input` to be a `Function` or `Object` issue with gtoken and pify? 是什么原因导致此JavaScript错误? - What could be causing this JavaScript error? 什么可能阻止我的 javascript click() function? - What could be blocking my javascript click() function? Google Chrome v8 使用什么缓和 function 来滚动到? - What easing function does Google Chrome v8 use for scrollTo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM