为什么我的卷轴不能顺利向上滚动
Why can't my my scroll scroll up smoothly?
首先,这里是索引.html
<html>
<head>
<title>Demo</title>
<link rel="stylesheet" type="text/css" href="stuff.css"/>
</head>
<body>
<div class=passage>
<h1>Getting Started</h1>
<p>
To get started, click one of the <a href="#" class="scrollup">four buttons</a> that are above. Each button will take you to its appropriate page.
</p><br>
<h1>Questions/Concerns</h1>
<p>
If any questions come to mind, please visit the <a href="help.html">help</a> page. Likewise, if one has any specific questions or concerns regarding the data, website, etc., please visit the <a href="contact.html">contact</a> page.
</p><br>
</div>
<script src="https://code.jquery.com/jquery-latest.js"></script>
</body>
</html>
这是东西.css
.passage {
margin-top: 40px;
margin-left: 200px;
margin-right: 200px;
border-radius: 25px;
float: left;
height: 1000px;
}
.passage p{
margin-left: 10px;
}
.passage h3{
font-style: bold;
}
.scrollup {
}
这是样式脚本.js
<!DOCTYPE HTML>
<html>
<body>
<script>
$(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;
});
});
</script>
</body>
</html>
所以我要做的是,当我按下index.html中的"四个按钮"时,index.html页面将平滑地滚动到顶部。不幸的是,这不会发生,它只是瞬移到顶部,没有缓慢的移动。当涉及到javascript时,我很笨拙,所以我想我会在这里问:当我单击"四个按钮"时,我做错了什么,无法将平滑的滚动移动到顶部?
谢谢大家,谢谢。
当你正确地编写样式脚本时.js它可以工作。
我尝试将您的 javascript 代码复制到 html 文件,如下所示,它工作正常。(为了检查目的,我在html上添加了一些元素。
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<link rel="stylesheet" type="text/css" href="stuff.css"/>
</head>
<body>
<div class=passage>
<h1>Getting Started</h1>
<p>
To get started, click one of the four buttons that are above. Each button will take you to its appropriate page.
</p><br>
<h1>Questions/Concerns</h1>
<p>
If any questions come to mind, please visit the <a href="help.html">help</a> page. Likewise, if one has any specific questions or concerns regarding the data, website, etc., please visit the <a href="contact.html">contact</a> page.
</p><br>
</div>
<div>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<p>:</p>
<a href="#" class="scrollup">four buttons</a>
</div>
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script>
$(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;
});
});
</script>
</body>
</html>
相关文章:
- "此网站似乎使用滚动链接定位效果.这可能不能很好地与异步平移一起工作;
- 如何在HTML / CSS中填充垂直和滚动中间窗格(Chrome可以工作,但不能Firefox)
- JQuery定位:我可以滚动到正确的位置一次,但不能滚动两次
- JQuery - 检查窗口何时位于顶部(用户不能再向上滚动)
- 检查可见性并使用jquery/javascript添加一个类,但不能依赖于滚动事件
- 为什么我的卷轴不能顺利向上滚动
- 滚动时淡入淡出;不能在移动浏览器中工作
- 导航锚点不'滚动jQuery时不能正确应用活动类
- 高库存滚动条没有'不能在svg foreignObject中工作
- Bootstrap滚动间谍和粘性导航不能一起工作
- 我的滚动加载没有'我不能在IE 8上工作
- jQuery'滚动前删除锚点'功能不能在firefox中工作,但在chrome、safari中可以完美工
- 使用javascript滚动在Ipad上不能快速运行
- Jquery滚动代码不能正常工作
- 滚动"位置:固定"Div位于页面上,但不能位于某个Div之上
- 不能让滚动条显示在Colorbox中
- 水平滚动导航条不能正常工作
- Jquery滚动导航不能'
- Jquery滚动不能正常工作
- 水平滚动不能垂直滚动