我想讓我的網站上的滾動向上和向下按鈕,但我必須缺少的東西。這裏是我的代碼...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仍然至少學習所有這些都非常綠色,有幫助嗎?