我的导航栏中有3个链接,无论何时按下,我都希望能够顺利滚动到页面上的区域。我已经设置了锚点,但我没有任何脚本编写经验,因此我需要实际平滑滚动的帮助。谁能告诉我我需要做什么?我还在这里创建了一个JSFIDDLE:https://jsfiddle.net/d9oxdxbo/
HTML
CREATE TABLE #TEST
(timefield datetime,
id int,
ChangeNum int)
INSERT INTO #TEST (TIMEFIELD, ID, CHANGENUM)
VALUES
('2014-07-03 00:00:00.000', 3, 0),
('2014-10-02 00:00:00.000', 3, 1),
('2014-11-27 00:00:00.000', 3, 2),
('2015-01-15 00:00:00.000', 3, 3),
('2015-02-14 00:00:00.000', 3, 4),
('2014-11-27 00:00:00.000', 2, 2),
('2015-01-15 00:00:00.000', 2, 3),
('2015-02-14 00:00:00.000', 2, 4),
('2014-10-02 00:00:00.000', 1, 1),
('2014-11-27 00:00:00.000', 1, 2),
('2015-01-15 00:00:00.000', 1, 3),
('2015-02-14 00:00:00.000', 1, 4)
CREATE TABLE #TEST2
(timefield datetime,
id int,
ChangeNum int)
DECLARE @ID int = (SELECT MIN(ID) FROM #TEST)
DECLARE @ChangeNum int = (SELECT MIN(ChangeNum) FROM #TEST WHERE @ID = ID)
DECLARE @TIMEFIELD datetime = (SELECT MIN(TIMEFIELD) FROM #TEST WHERE @ID = ID)
WHILE @ID <= (SELECT MAX(ID) FROM #TEST)
BEGIN
WHILE @TIMEFIELD <= (SELECT MAX(TIMEFIELD) FROM #TEST WHERE ID = @ID)
BEGIN
INSERT INTO #TEST2
SELECT @TIMEFIELD, @ID, @ChangeNum
SET @TIMEFIELD = DATEADD(DD, 1, @TIMEFIELD)
IF EXISTS (SELECT * FROM #TEST WHERE TIMEFIELD = @TIMEFIELD AND ID = @ID)
BEGIN
SET @ChangeNum = (SELECT ChangeNum FROM #TEST WHERE TIMEFIELD = @TIMEFIELD AND ID = @ID);
END
END
IF EXISTS (SELECT MIN(ID) FROM #TEST WHERE ID > @ID)
BEGIN
SET @ID = (SELECT MIN(ID) FROM #TEST WHERE ID > @ID)
SET @ChangeNum = (SELECT MIN(ChangeNum) FROM #TEST WHERE @ID = ID)
SET @TIMEFIELD = (SELECT MIN(TIMEFIELD) FROM #TEST WHERE @ID = ID)
END
END
SELECT * FROM #TEST2
CSS
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
<title>
</title>
</head>
<body>
<!-- Navigation Bar -->
<ul>
<li>
<a href="test_webpage.html#about">ABOUT
</a>
</li>
<li>
<a href="test_webpage.html#coupons">COUPONS
</a>
</li>
<li>
<a href="test_webpage.html#feedback">FEEDBACK
</a>
</li>
</ul>
<img src="https://preview.ibb.co/dr3y7v/vintage.png" height="660px" width="100%">
<h2>
<span style="background-color: rgba(26, 102, 255, 0.75)">BRINGING YOU CONVENIENCE
</span>
</h2>
<h3>
<span style="background-color: rgba(26, 102, 255, 0.75)">SINCE THE 2000's
</span>
</h3>
<div id='about'>
<a id="about" name='about'>
<div id='opaque'>
<img src="https://preview.ibb.co/bS5nja/gas_station_hero_image.jpg" height="680px" width="100%">
</div>
<h4>WHO WE ARE
</h4>
<div id='divp2'>
<p>WE ARE A SMALL CONVENIENCE STORE LOCATED IN THE HEART OF CARY, NORTH CAROLINA. WE SPECIALIZE IN CRAFT BEER AND EXQUISITE WINE. WE HAVE ALL YOUR QUICK GROCERY NEEDS. WE HAVE THE BEST PRICES IN OUR AREA GUARANTEED! COME VISIT US FOR A TRULY ENLIGHTENING EXPERIENCE! WE ARE ON GOOGLE SO IF YOU WANT TO SEE OUR REVIEWS OR GIVE US ONE, YOU CAN!
</p>
</div>
<div id='divp'>
<p>YOU MIGHT BE WONDERING, WHY SHOULD I COME HERE? WHAT MAKES THIS GAS STATION DIFFERENT FROM OTHER GAS STATIONS? WELL, WITH EXCELLENT STAFF, LOW PRICES, AND CLEAN FLOORS, THE BETTER QUESTION SHOULD BE, WHY SHOULDN'T I COME HERE! WE HOPE YOU COME TO OUR STORE AND HAVE A FABULOUS EXPERIENCE. IF YOU DO EXPERIENCE ANY DIFFICULTIES DURING YOUR TIME HERE, PLEASE FEEL FREE TO CONTACT THE MANAGER. HE WILL RESOLVE YOUR COMPLAINTS IN NO TIME!
</p>
</div>
</a>
</div>
<div id='coupons'>
<a id="coupons" name='coupons'>
<div style="float:left">
<img id='myImg' src="https://preview.ibb.co/jBYUxv/coupon1.png" id="i1" height="300px" width="600px">
<div id="myModal" class="modal">
<span class="close">×
</span>
<img class="modal-content" id="img01">
<div id="caption">
</div>
</div>
</div>
<div id='pformat'>
<p>COUPONS FOR YOU!
</p>
</div>
</a>
</div>
<div id='feedback'>
<a id="feedback" name='feedback'>
</a>
</div>
</body>
</html>
JS
body {
margin: 0px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: mediumblue;
font-family: monospace;
font-size: 15px;
text-align: center;
width: 100%;
top: 0;
}
li {
display: inline-block;
}
li a {
display: block;
color: white;
padding: 14px 75px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: darkblue;
font-style: italic;
}
img {
position: relative;
display: block;
}
h2 {
position: absolute;
top: 190px;
text-align: center;
width: 100%;
font-size: 65px;
color: white;
font-family: sans-serif;
font-style: italic;
}
h3 {
position: absolute;
top: 265px;
text-align: center;
width: 100%;
font-size: 65px;
color: white;
font-family: sans-serif;
font-style: italic;
}
h4 {
position: absolute;
text-align: center;
font-family: sans-serif;
font-style: italic;
width: 100%;
font-size: 60px;
top: 700px;
color: #1A66FF;
}
#divp2{
font-size: 20px;
font-family: 'hind';
position: absolute;
text-align: center;
margin-left: 150px;
margin-right: 150px;
color: #4d4d4d;
top: 900px;
margin-left: 150px;
margin-right: 150px;
font-weight: 0;
}
@font-face {
font-family: 'hind';
src: url('C:/Users/lakes/Desktop/hind2.ttf')
}
#pformat{
text-align: center;
margin-right: 30px;
font-size: 55px;
font-family: sans-serif;
margin-left: 620px;
position: absolute;
top: 1450px;
font-style: italic;
color: #1A66FF;
font-weight: bold;
}
#opaque {
opacity: .2;
}
#divp {
font-size: 20px;
font-family: 'hind';
position: absolute;
text-align: center;
top: 1075px;
margin-left: 150px;
margin-right: 150px;
color: #4d4d4d;
}
#myImg {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
#myImg:hover {
opacity: 0.7;
}
/* The Modal (background) */
.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0,0,0);
/* Fallback color */
background-color: rgba(0,0,0,0.9);
/* Black w/ opacity */
}
/* Modal Content (image) */
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}
/* Caption of Modal Image */
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}
/* Add Animation */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}
@-webkit-keyframes zoom {
from {
-webkit-transform: scale(0)}
to {
-webkit-transform: scale(1)}
}
@keyframes zoom {
from {
transform: scale(0.1)}
to {
transform: scale(1)}
}
/* The Close Button */
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
.modal-content {
width: 100%;
}
}
答案 0 :(得分:0)
尝试使用锚标记
<script type="text/javascript">
$(document).ready(function() {
$('a'). Click(function(e) {
e.preventDefault();
$('html, body').animate({
scrollTop: $('the link div').offset().top}, 'slow');
});
});
</script>