简单的滚动到顶部脚本无法正常工作

时间:2013-09-18 15:31:21

标签: javascript jquery scroll fade

唉,这让我很沮丧。我正在尝试使用简单的fadein滚动到顶部脚本,但它不会在我的网站上运行,也许有冲突?

HTML:

 <a href="#" class="scrollup">Scroll</a>

CSS:

.scrollup{
width: 15px;
height: 15px;
position: fixed;
top: 50px;
left: 15%;
display: none;
text-indent: -9999px;
background: url('../images/arrow.png') no-repeat;
z-index: 5000;
}

JQUERY:

$(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;
    });

});

网站:http://kaye.at/test/

1 个答案:

答案 0 :(得分:1)

您需要在$(function(){来电之前导入jquery库。

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>元素中添加<head>

此外,.no-touch .vs-container { overflow-x: hidden; }会阻止在窗口文档上触发滚动事件。