1

I copied and pasted the code for scroll to top in my webpage from the following website:

http://jsfiddle.net/neeklamy/RpPEe/

Even though the scroll to top button does not showing up, my webpage source code is as follows:

<!DOCTYPE html>
<html>
<head>
<title>Rough</title>
<style type ="text/css">
.scrollup {
width: 40px;
height: 40px;
position: fixed;
bottom: 50px;
right: 100px;
display: none;
text-indent: -9999px;
background: url('icon_top.png') no-repeat;
background-color: #000;
}
</style>
<script>
$(document).ready(function () {

$(window).scroll(function () {
    if ($(this).scrollTop() > 100) {
        $('.scrollup').fadeIn();
    } else {
        $('.scrollup').fadeOut();
    }
});

$('.scrollup').click(function () {
    $("html, body").animate({
        scrollTop: 0
    }, 600);
    return false;
});

});
</script>
</head>
<body>
<h1>Top of the page</h1>

<article style="height: 1000px">
<p style="margin-bottom: 600px">Scroll down the page&hellip;</p>
<p>Then click the box.</p>
<a href="#" class="scrollup">Scroll</a>
</article>
</body>
</html>
5
  • works like a charm for me, what browser are you in? Commented Apr 13, 2015 at 16:51
  • @whitebox google chrome Commented Apr 13, 2015 at 16:53
  • it works fine for me in Chrome, Firefox and IE 11 Commented Apr 13, 2015 at 16:53
  • Working perfectly for me, too! :) Commented Apr 13, 2015 at 16:55
  • Working for me in Chrome as well Commented Apr 13, 2015 at 16:56

2 Answers 2

5

You are missing jQuery, add the script tag like so:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>

or add it locally by downloading the library and adding it to your project files.

Working JSFiddle: http://jsfiddle.net/nayish/uLt7guvg/2/

Sign up to request clarification or add additional context in comments.

Comments

0

You're missing the 'icon_top.png' file. You must have that image in the same folder as the .html file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.