你这个网站的commonjs里的这段代码有问题。top变量值一直是0,导致置顶按钮一直隐藏。
改成var top=documentdocumentElementscrollTop;就可以了
修改完成了 你把 你的js全部替换下即可
<script type="text/javascript">var currentPosition, timer;
function GoTop() {
currentPosition = documentdocumentElementscrollTop;
currentPosition -= 50;
if (currentPosition > 0) {
windowscrollTo(0, currentPosition);
timer = setInterval("GoTop()", 10);
} else {
currentPosition = 0;
windowscrollTo(0);
windowclearInterval(timer);
}
}
var currentPosition2, timer2;
function GoBottom() {
currentPosition2 = documentdocumentElementscrollTop;
currentPosition2 += 50;
if (currentPosition2 <= 1000) {
windowscrollTo(0,currentPosition2);
timer2 = setInterval("GoBottom()", 100);
} else {
currentPosition = 1000;
windowscrollTo(0,1000);
windowclearInterval(timer2);
}
}
</script>使用介绍:
Elevatorjs是一个独立的标准JS库,并未借助JQuery之类的其他JS库,使用起来相当方便。元素的所有样式均可自行定义。
1首先需要创建Elevator对像,为其添加音乐子元素。代码如下:
[js] view plaincopy
<script>
// Elevator script included on the page, already
windowonload = function() {
var elevator = new Elevator({
mainAudio: '/src/to/audiomp3',
endAudio: '/src/to/end-audiomp3'
});
}
// You can run the elevator, by calling
elevatorelevate();
</script>
2接着添加HTML元素,通过单击该元素,可实现页面返回顶部的功能,代码如下:
[js] view plaincopy
<div class="elevator-button">Back to Top</div>
<script>
// Elevator script included on the page, already
windowonload = function() {
var elevator = new Elevator({
element: documentquerySelector('elevator-button'),
mainAudio: '/src/to/audiomp3',
endAudio: '/src/to/end-audiomp3'
});
}
</script>
3如果你不想使用音效,可以将音效替换成页面返回顶部所需时间间隔。代码如下:
[js] view plaincopy
<div class="elevator-button">Back to Top</div>
<script>
// Elevator script included on the page, already
windowonload = function() {
var elevator = new Elevator({
element: documentquerySelector('elevator-button'),
duration: 1000 // milliseconds
});
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)