简体   繁体   English

当我点击图片时如何让我的网站滚动到顶部

[英]How to get my website to scroll to the top when I click on an image

I wan't to have my website so that when you click on an image, it scrolls you back to the top of the page automatically.我不想拥有我的网站,这样当您单击图像时,它会自动将您滚动回页面顶部。 I've tried some versions I've seen online, but they haven't worked for me.我尝试了一些我在网上看到的版本,但它们对我不起作用。 I would be very grateful if you guys could give it a shot.如果你们能试一试,我将不胜感激。 Let me know if you have any questions.如果您有任何问题,请告诉我。 Thanks谢谢

 var click = 0; function checkClicks(imgs) { if (click == 0) { // Run your animation on first click document.getElementById('column1').classList.add('animate1') document.getElementById('column2').classList.add('animate2') document.getElementById('column3').classList.add('animate3') document.getElementById('column4').classList.add('animate4') document.getElementById('column5').classList.add('animate5') document.getElementById('column6').classList.add('animate6') document.getElementById('column7').classList.add('animate7') document.getElementById('column8').classList.add('animate8') document.getElementById('column9').classList.add('animate9') document.getElementById('footer').classList.add('animate10') document.getElementById('clickimage').classList.add('none') document.getElementById('abtproj').classList.add('animate11'); // hold Images for 1s setTimeout(function() { myFunction(imgs); }, 2050); } else { myFunction(imgs); } click = 1; } function myFunction(imgs) { var expandImg = document.getElementById("expandedImg"); expandImg.src = imgs.src; var imgParagraph = document.getElementById('img-paragraph'); imgParagraph.innerHTML = imgs.getAttribute("head"); expandImg.parentElement.style.display = "table-cell"; imgParagraph.style.display = 'table-cell'; } let target = document.querySelector('.column img'); target.addEventListener('mouseenter', () => document.querySelector('.column p').style.opacity = '0');
 * { margin: 0px; padding: 0px; border: 0px; }.topnav { background-color: rgb(84, 104, 217); overflow: hidden; font-family: 'futuralight'; font-weight: 900; }.topnav a { float: left; color: #f2f2f2; text-align: center; padding: 20px 21px; text-decoration: none; font-size: 19px; position: relative; left: 2%; }.topnav a:before { content: ""; position: absolute; width: 84%; height: 2px; bottom: 6px; left: 8%; background-color: white; visibility: hidden; transform: scaleX(0); transition: all 0.3s ease-in-out 0s; }.topnav a:hover:before { visibility: visible; transform: scaleX(1); }.topnav a.active-menu:before { content: ""; position: absolute; width: 84%; height: 2px; bottom: 6px; left: 8%; background-color: white; visibility: visible; transform: scaleX(1); transition: all 0.3s ease-in-out 0s; }.bigproj { text-align: center; font-size: 80px; }.proj { padding-top: 42px; font-family: 'playfair_displayregular'; font-weight: 900; } #clickimage { top: 220px; font-size: 40px; position: absolute; width: 100%; text-align: center; font-weight: 900; font-family: 'futuralight'; }.none { visibility: hidden; } #abtproj { top: 300px; font-size: 20px; position: absolute; left: 10%; width: 80%; }.animate11 { -webkit-animation: animate11 2s normal ease-out; animation: animate11 2s forwards normal ease-out; } @-webkit-keyframes animate11 { 100% { top: 240px; font-size: 20px; position: absolute; left: 10%; width: 80%; } } @keyframes animate11 { 100% { top: 240px; font-size: 20px; position: absolute; left: 10%; width: 80%; } }.column { float: left; width: 25%; position: relative; background-color: #EEF0FC; }.column p { position: absolute; color: #fff; display: flex; align-items: center; justify-content: center; top: 0; opacity: 0; transition: all.6s ease-out; margin: 0; left: 0; right: 0; bottom: 0; font-size: 31px; background: rgba(0, 0, 0, 0.5); pointer-events: none; }.column:hover p { opacity: 1; top: -7px; transition: all.6s ease-in-out; height: 100%; }.column img { cursor: pointer; background-color: black; position: relative; top: 0; vertical-align: bottom; transition: all.1s ease-out; }.column:hover img { box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034), 0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06), 0 22.3px 17.9px rgba(0, 0, 0, 0.072), 0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12); position: relative; top: -7px; transition: all.6s ease-in-out; } #totalbody { background-color: #EEF0FC; height: 600px; } /* Clear floats after the columns */.row:after { content: ""; display: table; clear: both; } /* The expanding image container */ #expandedImg { position: absolute; height: 400px; left: 300px; border-radius: 10px; box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034), 0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06), 0 22.3px 17.9px rgba(0, 0, 0, 0.072), 0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12); top: 585px; transform: translate(-50%, -50%); max-height: 430px; } /* Expanding image text */ /* image paragraph */ #img-paragraph { display: none; vertical-align: top; text-align: left; position: absolute; height: 400px; width: 50%; background-color: white; box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034), 0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06), 0 22.3px 17.9px rgba(0, 0, 0, 0.072), 0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12); border-radius: 7px; float: right; right: 30px; top: 385px; } #expanded-wrapper { width: 100%; } /* Closable button inside the expanded image */.row { position: absolute; top: 80px; }.head1 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head2 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head3 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head4 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head5 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head6 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head7 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head8 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head9 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head1::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head2::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head3::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head4::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head5::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head6::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head7::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head8::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head9::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.para1 { width: 90%; position: relative; left: 6%; font-size: 17px; top: 60px; font-family: 'futuralight'; } #column1 { position: absolute; width: 250px; float: left; left: 135px; top: 680px; }.animate1 { -webkit-animation: animate1 2s normal ease-out; animation: animate1 2s forwards normal ease-out; } @-webkit-keyframes animate1 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 680px; } 100% { position: absolute; width: 250px; float: left; left: 135px; top: 780px; } } @keyframes animate1 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 680px; } 100% { position: absolute; width: 250px; float: left; left: 135px; top: 780px; } } #column2 { position: absolute; width: 260px; float: left; left: 650px; top: 755px; }.animate2 { -webkit-animation: animate2 2s normal ease-out; animation: animate2 2s forwards normal ease-out; } @-webkit-keyframes animate2 { 0% { position: absolute; width: 260px; float: left; left: 650px; top: 755px; } 100% { position: absolute; width: 260px; float: left; left: 130px; top: 1475px; } } @keyframes animate2 { 0% { position: absolute; width: 260px; float: left; left: 650px; top: 755px; } 100% { position: absolute; width: 260px; float: left; left: 130px; top: 1475px; } } #column3 { position: absolute; width: 220px; float: left; left: 410px; top: 725px; }.animate3 { -webkit-animation: animate3 2s normal ease-out; animation: animate3 2s forwards normal ease-out; } @-webkit-keyframes animate3 { 0% { position: absolute; width: 220px; float: left; left: 410px; top: 725px; } 100% { position: absolute; width: 220px; float: left; left: 930px; top: 1475px; } } @keyframes animate3 { 0% { position: absolute; width: 220px; float: left; left: 410px; top: 725px; } 100% { position: absolute; width: 220px; float: left; left: 930px; top: 1475px; } } #column4 { position: absolute; width: 300px; float: left; left: 300px; top: 1055px; }.animate4 { -webkit-animation: animate4 2s normal ease-out; animation: animate4 2s forwards normal ease-out; } @-webkit-keyframes animate4 { 0% { position: absolute; width: 300px; float: left; left: 300px; top: 1055px; } 100% { position: absolute; width: 350px; float: left; left: 870px; top: 1135px; } } @keyframes animate4 { 0% { position: absolute; width: 300px; float: left; left: 300px; top: 1055px; } 100% { position: absolute; width: 350px; float: left; left: 870px; top: 1135px; } } #column5 { position: absolute; width: 350px; float: left; left: 470px; top: 425px; }.animate5 { -webkit-animation: animate5 2s normal ease-out; animation: animate5 2s forwards normal ease-out; } @-webkit-keyframes animate5 { 0% { position: absolute; width: 350px; float: left; left: 470px; top: 425px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1135px; } } @keyframes animate5 { 0% { position: absolute; width: 350px; float: left; left: 470px; top: 425px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1135px; } } #column6 { position: absolute; width: 360px; float: left; left: 890px; top: 435px; }.animate6 { -webkit-animation: animate6 2s normal ease-out; animation: animate6 2s forwards normal ease-out; } @-webkit-keyframes animate6 { 0% { position: absolute; width: 360px; float: left; left: 890px; top: 435px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1435px; } } @keyframes animate6 { 0% { position: absolute; width: 360px; float: left; left: 890px; top: 435px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1435px; } } #column7 { position: absolute; width: 350px; float: left; left: 800px; top: 1025px; }.animate7 { -webkit-animation: animate7 2s normal ease-out; animation: animate7 2s forwards normal ease-out; } @-webkit-keyframes animate7 { 0% { position: absolute; width: 350px; float: left; left: 800px; top: 1025px; } 100% { position: absolute; width: 250px; float: left; left: 535px; top: 880px; } } @keyframes animate7 { 0% { position: absolute; width: 350px; float: left; left: 800px; top: 1025px; } 100% { position: absolute; width: 250px; float: left; left: 535px; top: 880px; } } #column8 { position: absolute; width: 250px; float: left; left: 135px; top: 500px; }.animate8 { -webkit-animation: animate8 2s normal ease-out; animation: animate8 2s forwards normal ease-out; } @-webkit-keyframes animate8 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 500px; } 100% { position: absolute; width: 250px; float: left; left: 935px; top: 900px; } } @keyframes animate8 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 500px; } 100% { position: absolute; width: 250px; float: left; left: 935px; top: 900px; } } #column9 { position: absolute; width: 316px; float: left; left: 933px; top: 715px; }.animate9 { -webkit-animation: animate9 2s normal ease-out; animation: animate9 2s forwards normal ease-out; } @-webkit-keyframes animate9 { 0% { position: absolute; width: 316px; float: left; left: 933px; top: 715px; } 100% { position: absolute; width: 316px; float: left; left: 100px; top: 1150px; } } @keyframes animate9 { 0% { position: absolute; width: 316px; float: left; left: 933px; top: 715px; } 100% { position: absolute; width: 316px; float: left; left: 100px; top: 1150px; } } #footer { position: absolute; background-color: rgb(84, 104, 217); height: 80px; width: 100%; top: 1500px; color: white; overflow: hidden; }.animate10 { -webkit-animation: animate10 1s normal ease-out; animation: animate10 1s forwards normal ease-out; } @-webkit-keyframes animate10 { 100% { position: absolute; top: 1900px; } } @keyframes animate10 { 100% { position: absolute; top: 1900px; } }.footwords { top: 32px; font-family: 'playfair_displayregular'; position: absolute; left: 6%; }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="../CSS/styleprojects.css" /> <script src='../Javascript/script.js'></script> <script src='../Javascript/fix.js'></script> <script src='../Javascript/jquery-3.5.1.min.js'></script> <:-- Global site tag (gtag.js) - Google Analytics --> <script async src="https.//www?googletagmanager.com/gtag/js.id=UA-168595753-1"></script> <script> window;dataLayer = window.dataLayer || []; function gtag() { dataLayer,push(arguments); } gtag('js', new Date()); gtag('config': 'UA-168595753-1'). </script> <title>Projects</title> <link rel="shortcut icon" type='image/png' href="https.//www.favicon.cc/logo3d/589118.png"> </head> <body id='totalbody'> <header class="topnav" id="topnav"> <a class="link" href="../index.html">Home</a> <a class="link" href="academics.html">Academics</a> <a class="active-menu" href="projects,html">Projects</a> <a class="link" href="communityservice.html">Community Service</a> </header> <div class='bigproj'> <p class='proj'> Projects </p> </div> <div id='clickimghold'> <p id='clickimage'>Click On The Images Below</p> </div> <div> <p id='abtproj'>Lorem, ipsum dolor sit amet consectetur adipisici ng elit. Dicta, libero. Recusandae provident est quam quisquam. Sequi itaque suscipit tempore corrupti officia maxime nihil consequatur perspiciatis repellat placeat sed, voluptatum vitae?lor em Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro similique. prov ident libero laudantium amet odit unde dolor eaque earum qui impedit possimus natus est distinctio commodi quod aut numquam temporibus. </p> </div> <div> <div id="expanded-wrapper"> <img id="expandedImg"> <p id="img-paragraph"></p> </div> </div> <div class="row"> <div class="column" id='column1'> <img class='arcadeimg' src=":./Images/arcade,jpeg" alt="Arcade" style="width?100%" head="<p class='head1'> Parapraph #1 </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus. recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Arcade Machine</p> </div> <div class="column" id='column2'> <img src=":./Images/car,png" alt="Car" style="width?100%" head="<p class='head2'> Parapraph #2 </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus. recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Electric Car</p> </div> <div class="column" id='column3'> <img src=":./Images/pinball,jpeg" alt="Pinball Machine" style="width?100%" head="<p class='head3'> Parapraph #3 </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus. recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Pinball Machine</p> </div> <div class="column" id='column4'> <img src=":./Images/vending,jpeg" alt="Vending Machine" style="width?100%" head="<p class='head4'> Parapraph #4 </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus. recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Vending Machine</p> </div> <div class="column" id='column5'> <img src=":./Images/sriraques,jpeg" alt="Sriracha Quesadillas" style="width?100%" head="<p class='head5'> Parapraph #5 </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus: recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Sriracha Quesadillas</p> </div> <div class="column" id='column6'> <img src="https://miro.medium,com/max/1000/0*kBHpKva09AsGj7RQ" alt="Lights" style="width?100%" head="<p class='head6'> web code </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus: recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Website Development</p> </div> <div class="column" id='column7'> <img src="https.//cdn:britannica.com/77/170477-050-1C747EE3/Laptop-computer,jpg" alt="Lights" style="width?100%" head="<p class='head7'> Web Server </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus: recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Web Server</p> </div> <div class="column" id='column8'> <img src="https?//nctennis.com/common/controls/image_handler:aspx.thumb_id=13&image_path=/images/2018/11/27/Wheelchair,jpg" alt="Lights" style="width?100%" head="<p class='head8'> Adaptive Tennis </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus: recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this)."> <p>Adaptive Tennis</p> </div> <div class="column" id='column9'> <img src="https://opticsmag.com/wp-content/uploads/2019/04/a-telescope,jpg" alt="Lights" style="width?100%" head="<p class='head9'> telescope </p><p class='para1'> Lorem ipsum dolor si t amet consectetur adipisicing elit; Sed natus. recusandae veritatis ipsum quia commodi tenetur laboriosam pariatur nihil incidunt architecto velit so luta placeat repellat asperiores iure eos dolorum fugiat.</p>" onclick="checkClicks(this);"> <p>Telescope</p> </div> </div> </div> <footer id='footer'> <p class='footwords'> © 2020 By R. Proudly Individually Coded. </p> </footer> </body> </html>

You can simply add a window.scrollTo({top: 0, behavior: 'smooth')} handler on the click listener for each image that can trigger scroll.您可以简单地在每个可以触发滚动的图像的点击侦听器上添加一个window.scrollTo({top: 0, behavior: 'smooth')}处理程序。 In this example, I've given the images that trigger scroll the class scroll-triggering .在这个例子中,我给了触发滚动的图像 class scroll-triggering

 // Added section document.querySelectorAll('img.scroll-triggering').forEach(img => { img.addEventListener('click', e => { window.scrollTo({ top: 0, behavior: 'smooth' }) }) }) // End of added section var click = 0; function checkClicks(imgs) { if (click == 0) { // Run your animation on first click document.getElementById('column1').classList.add('animate1') document.getElementById('column2').classList.add('animate2') document.getElementById('column3').classList.add('animate3') document.getElementById('column4').classList.add('animate4') document.getElementById('column5').classList.add('animate5') document.getElementById('column6').classList.add('animate6') document.getElementById('column7').classList.add('animate7') document.getElementById('column8').classList.add('animate8') document.getElementById('column9').classList.add('animate9') document.getElementById('footer').classList.add('animate10') document.getElementById('clickimage').classList.add('none') document.getElementById('abtproj').classList.add('animate11'); // hold Images for 1s setTimeout(function() { myFunction(imgs); }, 2050); } else { myFunction(imgs); } click = 1; } function myFunction(imgs) { var expandImg = document.getElementById("expandedImg"); expandImg.src = imgs.src; var imgParagraph = document.getElementById('img-paragraph'); imgParagraph.innerHTML = imgs.getAttribute("head"); expandImg.parentElement.style.display = "table-cell"; imgParagraph.style.display = 'table-cell'; } let target = document.querySelector('.column img'); target.addEventListener('mouseenter', () => document.querySelector('.column p').style.opacity = '0');
 * { margin: 0px; padding: 0px; border: 0px; }.topnav { background-color: rgb(84, 104, 217); overflow: hidden; font-family: 'futuralight'; font-weight: 900; }.topnav a { float: left; color: #f2f2f2; text-align: center; padding: 20px 21px; text-decoration: none; font-size: 19px; position: relative; left: 2%; }.topnav a:before { content: ""; position: absolute; width: 84%; height: 2px; bottom: 6px; left: 8%; background-color: white; visibility: hidden; transform: scaleX(0); transition: all 0.3s ease-in-out 0s; }.topnav a:hover:before { visibility: visible; transform: scaleX(1); }.topnav a.active-menu:before { content: ""; position: absolute; width: 84%; height: 2px; bottom: 6px; left: 8%; background-color: white; visibility: visible; transform: scaleX(1); transition: all 0.3s ease-in-out 0s; }.bigproj { text-align: center; font-size: 80px; }.proj { padding-top: 42px; font-family: 'playfair_displayregular'; font-weight: 900; } #clickimage { top: 220px; font-size: 40px; position: absolute; width: 100%; text-align: center; font-weight: 900; font-family: 'futuralight'; }.none { visibility: hidden; } #abtproj { top: 300px; font-size: 20px; position: absolute; left: 10%; width: 80%; }.animate11 { -webkit-animation: animate11 2s normal ease-out; animation: animate11 2s forwards normal ease-out; } @-webkit-keyframes animate11 { 100% { top: 240px; font-size: 20px; position: absolute; left: 10%; width: 80%; } } @keyframes animate11 { 100% { top: 240px; font-size: 20px; position: absolute; left: 10%; width: 80%; } }.column { float: left; width: 25%; position: relative; background-color: #EEF0FC; }.column p { position: absolute; color: #fff; display: flex; align-items: center; justify-content: center; top: 0; opacity: 0; transition: all.6s ease-out; margin: 0; left: 0; right: 0; bottom: 0; font-size: 31px; background: rgba(0, 0, 0, 0.5); pointer-events: none; }.column:hover p { opacity: 1; top: -7px; transition: all.6s ease-in-out; height: 100%; }.column img { cursor: pointer; background-color: black; position: relative; top: 0; vertical-align: bottom; transition: all.1s ease-out; }.column:hover img { box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034), 0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06), 0 22.3px 17.9px rgba(0, 0, 0, 0.072), 0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12); position: relative; top: -7px; transition: all.6s ease-in-out; } #totalbody { background-color: #EEF0FC; height: 600px; } /* Clear floats after the columns */.row:after { content: ""; display: table; clear: both; } /* The expanding image container */ #expandedImg { position: absolute; height: 400px; left: 300px; border-radius: 10px; box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034), 0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06), 0 22.3px 17.9px rgba(0, 0, 0, 0.072), 0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12); top: 585px; transform: translate(-50%, -50%); max-height: 430px; } /* Expanding image text */ /* image paragraph */ #img-paragraph { display: none; vertical-align: top; text-align: left; position: absolute; height: 400px; width: 50%; background-color: white; box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034), 0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06), 0 22.3px 17.9px rgba(0, 0, 0, 0.072), 0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12); border-radius: 7px; float: right; right: 30px; top: 385px; } #expanded-wrapper { width: 100%; } /* Closable button inside the expanded image */.row { position: absolute; top: 80px; }.head1 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head2 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head3 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head4 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head5 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head6 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head7 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head8 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head9 { position: relative; left: 12px; top: 16px; color: rgb(84, 104, 217); font-weight: 900; font-size: 40px; font-family: 'futuralight'; text-decoration: none; line-height: 1; padding-left: 4%; padding-top: 30px; }.head1::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head2::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head3::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head4::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head5::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head6::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head7::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head8::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.head9::before { content: ''; background-color: rgb(84, 104, 217); width: 12px; height: 100%; position: absolute; right: 100%; bottom: -16px; }.para1 { width: 90%; position: relative; left: 6%; font-size: 17px; top: 60px; font-family: 'futuralight'; } #column1 { position: absolute; width: 250px; float: left; left: 135px; top: 680px; }.animate1 { -webkit-animation: animate1 2s normal ease-out; animation: animate1 2s forwards normal ease-out; } @-webkit-keyframes animate1 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 680px; } 100% { position: absolute; width: 250px; float: left; left: 135px; top: 780px; } } @keyframes animate1 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 680px; } 100% { position: absolute; width: 250px; float: left; left: 135px; top: 780px; } } #column2 { position: absolute; width: 260px; float: left; left: 650px; top: 755px; }.animate2 { -webkit-animation: animate2 2s normal ease-out; animation: animate2 2s forwards normal ease-out; } @-webkit-keyframes animate2 { 0% { position: absolute; width: 260px; float: left; left: 650px; top: 755px; } 100% { position: absolute; width: 260px; float: left; left: 130px; top: 1475px; } } @keyframes animate2 { 0% { position: absolute; width: 260px; float: left; left: 650px; top: 755px; } 100% { position: absolute; width: 260px; float: left; left: 130px; top: 1475px; } } #column3 { position: absolute; width: 220px; float: left; left: 410px; top: 725px; }.animate3 { -webkit-animation: animate3 2s normal ease-out; animation: animate3 2s forwards normal ease-out; } @-webkit-keyframes animate3 { 0% { position: absolute; width: 220px; float: left; left: 410px; top: 725px; } 100% { position: absolute; width: 220px; float: left; left: 930px; top: 1475px; } } @keyframes animate3 { 0% { position: absolute; width: 220px; float: left; left: 410px; top: 725px; } 100% { position: absolute; width: 220px; float: left; left: 930px; top: 1475px; } } #column4 { position: absolute; width: 300px; float: left; left: 300px; top: 1055px; }.animate4 { -webkit-animation: animate4 2s normal ease-out; animation: animate4 2s forwards normal ease-out; } @-webkit-keyframes animate4 { 0% { position: absolute; width: 300px; float: left; left: 300px; top: 1055px; } 100% { position: absolute; width: 350px; float: left; left: 870px; top: 1135px; } } @keyframes animate4 { 0% { position: absolute; width: 300px; float: left; left: 300px; top: 1055px; } 100% { position: absolute; width: 350px; float: left; left: 870px; top: 1135px; } } #column5 { position: absolute; width: 350px; float: left; left: 470px; top: 425px; }.animate5 { -webkit-animation: animate5 2s normal ease-out; animation: animate5 2s forwards normal ease-out; } @-webkit-keyframes animate5 { 0% { position: absolute; width: 350px; float: left; left: 470px; top: 425px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1135px; } } @keyframes animate5 { 0% { position: absolute; width: 350px; float: left; left: 470px; top: 425px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1135px; } } #column6 { position: absolute; width: 360px; float: left; left: 890px; top: 435px; }.animate6 { -webkit-animation: animate6 2s normal ease-out; animation: animate6 2s forwards normal ease-out; } @-webkit-keyframes animate6 { 0% { position: absolute; width: 360px; float: left; left: 890px; top: 435px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1435px; } } @keyframes animate6 { 0% { position: absolute; width: 360px; float: left; left: 890px; top: 435px; } 100% { position: absolute; width: 350px; float: left; left: 470px; top: 1435px; } } #column7 { position: absolute; width: 350px; float: left; left: 800px; top: 1025px; }.animate7 { -webkit-animation: animate7 2s normal ease-out; animation: animate7 2s forwards normal ease-out; } @-webkit-keyframes animate7 { 0% { position: absolute; width: 350px; float: left; left: 800px; top: 1025px; } 100% { position: absolute; width: 250px; float: left; left: 535px; top: 880px; } } @keyframes animate7 { 0% { position: absolute; width: 350px; float: left; left: 800px; top: 1025px; } 100% { position: absolute; width: 250px; float: left; left: 535px; top: 880px; } } #column8 { position: absolute; width: 250px; float: left; left: 135px; top: 500px; }.animate8 { -webkit-animation: animate8 2s normal ease-out; animation: animate8 2s forwards normal ease-out; } @-webkit-keyframes animate8 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 500px; } 100% { position: absolute; width: 250px; float: left; left: 935px; top: 900px; } } @keyframes animate8 { 0% { position: absolute; width: 250px; float: left; left: 135px; top: 500px; } 100% { position: absolute; width: 250px; float: left; left: 935px; top: 900px; } } #column9 { position: absolute; width: 316px; float: left; left: 933px; top: 715px; }.animate9 { -webkit-animation: animate9 2s normal ease-out; animation: animate9 2s forwards normal ease-out; } @-webkit-keyframes animate9 { 0% { position: absolute; width: 316px; float: left; left: 933px; top: 715px; } 100% { position: absolute; width: 316px; float: left; left: 100px; top: 1150px; } } @keyframes animate9 { 0% { position: absolute; width: 316px; float: left; left: 933px; top: 715px; } 100% { position: absolute; width: 316px; float: left; left: 100px; top: 1150px; } } #footer { position: absolute; background-color: rgb(84, 104, 217); height: 80px; width: 100%; top: 1500px; color: white; overflow: hidden; }.animate10 { -webkit-animation: animate10 1s normal ease-out; animation: animate10 1s forwards normal ease-out; } @-webkit-keyframes animate10 { 100% { position: absolute; top: 1900px; } } @keyframes animate10 { 100% { position: absolute; top: 1900px; } }.footwords { top: 32px; font-family: 'playfair_displayregular'; position: absolute; left: 6%; }
 <body id='totalbody'> <header class="topnav" id="topnav"> <a class="link" href="../index.html">Home</a> <a class="link" href="academics.html">Academics</a> <a class="active-menu" href="projects.html">Projects</a> <a class="link" href="communityservice.html">Community Service</a> </header> <div class='bigproj'> <p class='proj'> Projects </p> </div> <div id='clickimghold'> <p id='clickimage'>Click On The Images Below</p> </div> <div> <p id='abtproj'> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dicta, libero. Recusandae provident est quam quisquam, Sequi itaque suscipit tempore corrupti officia maxime nihil consequatur perspiciatis repellat placeat sed. voluptatum vitae.lor em Lorem ipsum </p> </div> <div> <div id="expanded-wrapper"> <img id="expandedImg"> <p id="img-paragraph"></p> </div> </div> <div class="row"> <div class="column" id='column1'> <img class='arcadeimg' src="../Images/arcade:jpeg" alt="Arcade" style="width;100%" onclick="checkClicks(this)."> <p>Arcade Machine</p> </div> <div class="column" id='column2'> <img src="../Images/car:png" alt="Car" style="width;100%" onclick="checkClicks(this)."> <p>Electric Car</p> </div> <div class="column" id='column3'> <img src="../Images/pinball:jpeg" alt="Pinball Machine" style="width;100%" onclick="checkClicks(this)."> <p>Pinball Machine</p> </div> <div class="column" id='column4'> <img src="../Images/vending:jpeg" alt="Vending Machine" style="width;100%" onclick="checkClicks(this)."> <p>Vending Machine</p> </div> <div class="column" id='column5'> <img src="../Images/sriraques:jpeg" alt="Sriracha Quesadillas" style="width;100%" onclick="checkClicks(this):"> <p>Sriracha Quesadillas</p> </div> <div class="column" id='column6'> <img class="scroll-triggering" src="https.//miro.medium:com/max/1000/0*kBHpKva09AsGj7RQ" alt="Lights" style="width;100%" onclick="checkClicks(this):"> <p>Website Development</p> </div> <div class="column" id='column7'> <img class="scroll-triggering" src="https.//cdn.britannica.com/77/170477-050-1C747EE3/Laptop-computer:jpg" alt="Lights" style="width;100%" onclick="checkClicks(this):"> <p>Web Server</p> </div> <div class="column" id='column8'> <img class="scroll-triggering" src="https.//nctennis.com/common/controls/image_handler?aspx.thumb_id=13&image_path=/images/2018/11/27/Wheelchair:jpg" alt="Lights" style="width;100%" onclick="checkClicks(this):"> <p>Adaptive Tennis</p> </div> <div class="column" id='column9'> <img class="scroll-triggering" src="https.//opticsmag.com/wp-content/uploads/2019/04/a-telescope:jpg" alt="Lights" style="width;100%" onclick="checkClicks(this)."> <p>Telescope</p> </div> </div> <footer id='footer'> <p class='footwords'> © 2020 By R. Proudly Individually Coded. </p> </footer> </body>

Some concerns, although unrelated to your original question, on your code:尽管与您的原始问题无关,但您的代码存在一些问题:

  • Try to adjust sizes (including font-size , width , etc.) using relative units (eg rem , em , % , etc.) and not hard-coded values尝试使用相对单位(例如remem%等)而不是硬编码值来调整大小(包括font-sizewidth等)
  • Headers should use the tag h1 - h6 , not p wrapped by a div标头应该使用标签h1 - h6 ,而不是pdiv包裹
  • You should check again the usage of the head attribute as I can't find any official resources mentioning that this is valid.您应该再次检查head属性的用法,因为我找不到任何官方资源提到这是有效的。 The value of the attribute in your code is also strange.您的代码中的属性值也很奇怪。

 img { display:inline-block; vertical-align:middle; width:100%; max-width:450px; margin-bottom:100px; scroll-behavior:smooth; }
 <a class="img" href="#"> <img src="https://nctennis.com/common/controls/image_handler.aspx?thumb_id=13&image_path=/images/2018/11/27/Wheelchair.jpg" </a> <a class="img" href="#"> <img src="https://nctennis.com/common/controls/image_handler.aspx?thumb_id=13&image_path=/images/2018/11/27/Wheelchair.jpg" </a> <a class="img" href="#"> <img src="https://nctennis.com/common/controls/image_handler.aspx?thumb_id=13&image_path=/images/2018/11/27/Wheelchair.jpg" </a> <a class="img" href="#"> <img src="https://nctennis.com/common/controls/image_handler.aspx?thumb_id=13&image_path=/images/2018/11/27/Wheelchair.jpg" </a> <a class="img" href="#"> <img src="https://nctennis.com/common/controls/image_handler.aspx?thumb_id=13&image_path=/images/2018/11/27/Wheelchair.jpg" </a> <a class="img" href="#"> <img src="https://nctennis.com/common/controls/image_handler.aspx?thumb_id=13&image_path=/images/2018/11/27/Wheelchair.jpg" </a> <a class="img" href="#"> <img src="https://nctennis.com/common/controls/image_handler.aspx?thumb_id=13&image_path=/images/2018/11/27/Wheelchair.jpg" </a>

Give href="#" to your a tags then it goes to the top.将 href="#" 给您的 a 标签,然后它会转到顶部。 Then if you want to make it smoother add scroll-behavior:smooth to your css file.然后,如果您想让它更平滑,请将 scroll-behavior:smooth 添加到您的 css 文件中。 https://caniuse.com/#search=scroll-behavior https://caniuse.com/#search=scroll-behavior

 a { display:block; width:500px; height:500px; scroll-behavior: smooth; }
 <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a> <a href="#">Image</a>

Smooth scrolling when clicking an anchor link 单击锚链接时平滑滚动

Please check the link above, u can always add an id for a dom element at the very top of the page and make an anchor link to it on your image.请检查上面的链接,你总是可以在页面的最顶部为 dom 元素添加一个 id,并在你的图像上创建一个指向它的锚链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我单击链接时,我的网站总是向上滚动吗? - My website alway scroll up when i click link? 为什么当我在页面顶部滚动并单击附加表格的链接时,它会向下滚动 - Why when i scroll top my page and click link which append a form it scroll me down 单击后如何使图像滑块重置其自动滚动计时器? - How do I get my image slider to reset its auto-scroll timer after a click? 滚动时如何保持顶部菜单固定 - How to keep my top menu stay fixed when i scroll 单击按钮时如何重定向到我的网站? - How can I redirect to my website when I click a button? 完美滚动到顶部。 但是当我向下滚动并单击页面上的任意位置时,滚动再次移至顶部 - Perfectly scroll to top. but when i scroll down and click anywhere on page, again scroll moves to the top 如何获得锚链接,使其在向下滚动时像在其上一样平滑地向上滚动? - How can I get my anchor link to scroll smoothly back up top like it does when it goes down? 如何使导航栏平滑滚动到页面顶部,请单击 - how can I make my navbar scroll smoothly to the top on page click 当页面动画到顶部以获得目标位置时,如何在单击..时获得窗口滚动单位 - How to get window scroll unit on click .. when a page is animating to top for target position 滚动到我的网站顶部按钮不起作用 - Scroll to top button in my website is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM