Tus*_*and 1 html javascript css
我从以下网站复制并粘贴代码以滚动到我的网页顶部:
http://jsfiddle.net/neeklamy/RpPEe/
即使滚动到顶部按钮没有显示,我的网页源代码如下:
<!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…</p>
<p>Then click the box.</p>
<a href="#" class="scrollup">Scroll</a>
</article>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
你缺少jQuery,像这样添加脚本标签:
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
Run Code Online (Sandbox Code Playgroud)
或者通过下载库并将其添加到项目文件中在本地添加它.
工作JSFiddle:http://jsfiddle.net/nayish/uLt7guvg/2/
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |