我想让我的网站上的滚动向上和向下按钮,但我必须缺少的东西。这里是我的代码...jquery向上/向下滚动按钮不起作用
HTML:
<body>
<div id="middle-body">test</div>
<div id="toTop">^</div>
<div id="toBottom">^</div>
</body>
JS/jQuery的:
var scrolled=0;
$(document).ready(function(){
$("#toTop").on("click" ,function(){
scrolled=scrolled+300;
$("#middle-body").animate({
scrollTop: scrolled
});
});
$("#toBottom").on("click" ,function(){
scrolled=scrolled-300;
$("#middle-body").animate({
scrollTop: scrolled
});
});
});
CSS:
#middle-body {
color: white;
background: #555;
height: 900px;
}
#toTop {
cursor: pointer;
display: block;
font-size: 100px;
line-height: 100px;
font-weight: bold;
position: fixed;
top: 40%;
right: 10px;
text-align: center;
}
#toBottom {
cursor: pointer;
display: block;
font-size: 100px;
font-weight: bold;
line-height: 100px;
position: fixed;
bottom: 20%;
right: 10px;
text-align: center;
transform: rotate(-180deg);
-webkit-transform: rotate(-180deg);
-moz-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
-o-transform: rotate(-180deg);
}
#toTop:hover, #toBottom:hover {
color: white;
}
和最后但并非最fiddle! IM仍然至少学习所有这些都非常绿色,有帮助吗?