javascript Uncaught ReferenceError: $ is not defined
<!DOCTYPEhtml><html><head><title>*_*!</title><metacharset="utf-8"/><styletype="text/c...
<!DOCTYPE html>
<html>
<head>
<title>*_*!</title>
<meta charset="utf-8" />
<style type="text/css">
#back-to-top {
position:fixed;
right:50px;
z-index:9;
width:70px;
height:900px;
background:url(scroll.gif);
transition:0.5s;
cursor:pointer;
}
</style>
</head>
<body>
<!--回到顶部-->
<div id="back-to-top" class="red" data-scroll="body" style="top:-46px;color:red;">回到顶部
</div>
<!--撑开网页代码-->
<p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p>
<script type="text/javascript">
window.onload = function () {
// 利用 data-scroll 属性,滚动到任意 dom 元素
$.scrollto = function (scrolldom, scrolltime) {
$(scrolldom).click(function () {
var scrolltodom = $(this).attr("data-scroll");
$(this).addClass("active").siblings().removeClass("active");
$('html, body').animate({
scrollTop: $(scrolltodom).offset().top
}, scrolltime);
return false;
});
};
//判断位置控制 返回顶部的显隐
if ($(window).width() > 800) {//如果窗体的宽度大于800
var backTo = $("#back-to-top");//获取back-to-top对象
var backHeight = $(window).height() - 980 + 'px';//让window高度减980
$(window).scroll(function () {
if ($(window).scrollTop() > 700 && backTo.css('top') === '-900px') {
backTo.css('top', backHeight);
}
else if ($(window).scrollTop() <= 700 && backTo.css('top') !== '-900px') {
backTo.css('top', '-900px');
}
});
}
//启用
$.scrollto("#back-to-top", 800);
}
</script>
</body>
</html> 展开
<html>
<head>
<title>*_*!</title>
<meta charset="utf-8" />
<style type="text/css">
#back-to-top {
position:fixed;
right:50px;
z-index:9;
width:70px;
height:900px;
background:url(scroll.gif);
transition:0.5s;
cursor:pointer;
}
</style>
</head>
<body>
<!--回到顶部-->
<div id="back-to-top" class="red" data-scroll="body" style="top:-46px;color:red;">回到顶部
</div>
<!--撑开网页代码-->
<p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p><p>hello</p>
<script type="text/javascript">
window.onload = function () {
// 利用 data-scroll 属性,滚动到任意 dom 元素
$.scrollto = function (scrolldom, scrolltime) {
$(scrolldom).click(function () {
var scrolltodom = $(this).attr("data-scroll");
$(this).addClass("active").siblings().removeClass("active");
$('html, body').animate({
scrollTop: $(scrolltodom).offset().top
}, scrolltime);
return false;
});
};
//判断位置控制 返回顶部的显隐
if ($(window).width() > 800) {//如果窗体的宽度大于800
var backTo = $("#back-to-top");//获取back-to-top对象
var backHeight = $(window).height() - 980 + 'px';//让window高度减980
$(window).scroll(function () {
if ($(window).scrollTop() > 700 && backTo.css('top') === '-900px') {
backTo.css('top', backHeight);
}
else if ($(window).scrollTop() <= 700 && backTo.css('top') !== '-900px') {
backTo.css('top', '-900px');
}
});
}
//启用
$.scrollto("#back-to-top", 800);
}
</script>
</body>
</html> 展开
3个回答
展开全部
</style>的下面插入一行:
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询