joaquins Posted September 15, 2022 Share Posted September 15, 2022 (edited) Hello, I am trying to create 3 scroll anchor links to link to the next section on a specific page. I am using the following code and injecting it into the page header, but it only creates the anchor link from section 1 to 2, could someone help me figure out how to link section 2 to section 3 and from section 3 to back to top? <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(function() { $("#page>article>section:first-child").append('<a href="#" class="next-section"><i class="fa fa-angle-down" aria-hidden="true"></i></a>'); $('a.next-section').on('click', function(e) { e.preventDefault(); $('html, body').animate({ scrollTop: $(" #page>article>section:first-child").next().offset().top}, 500, 'linear'); }); }); </script> <style> article>section:first-child a.next-section { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 2; display: inline-block; color: #fff; font : normal 400 20px/1 'Josefin Sans', sans-serif; letter-spacing: .1em; text-decoration: none; transition: opacity .3s; animation: fade_move_down 4s ease-in-out infinite; background-color: rgba(0,0,0,0.5); width: 150px; padding-bottom: 20px; text-align: center; font-size: 50px; } </style> Many thanks! Edited September 15, 2022 by joaquins clarification Link to comment
Beyondspace Posted September 17, 2022 Share Posted September 17, 2022 On 9/16/2022 at 5:37 AM, joaquins said: Hello, I am trying to create 3 scroll anchor links to link to the next section on a specific page. I am using the following code and injecting it into the page header, but it only creates the anchor link from section 1 to 2, could someone help me figure out how to link section 2 to section 3 and from section 3 to back to top? <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(function() { $("#page>article>section:first-child").append('<a href="#" class="next-section"><i class="fa fa-angle-down" aria-hidden="true"></i></a>'); $('a.next-section').on('click', function(e) { e.preventDefault(); $('html, body').animate({ scrollTop: $(" #page>article>section:first-child").next().offset().top}, 500, 'linear'); }); }); </script> <style> article>section:first-child a.next-section { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 2; display: inline-block; color: #fff; font : normal 400 20px/1 'Josefin Sans', sans-serif; letter-spacing: .1em; text-decoration: none; transition: opacity .3s; animation: fade_move_down 4s ease-in-out infinite; background-color: rgba(0,0,0,0.5); width: 150px; padding-bottom: 20px; text-align: center; font-size: 50px; } </style> Many thanks! Have you tried adding it to footer of code injection or run the following code to make sure that your code only run after the dom in load completely? <script> (funtion(){ window.addEventListener('DOMContentLoaded', () => { //Your code }) })() </script> BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox, video lightbox and much more) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace (+100 Spark plugin customisations) 🥳 Freemium Squarespace Widget Templates (+1000 Elfsight Templates) If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
joaquins Posted September 17, 2022 Author Share Posted September 17, 2022 @bangank36 Thanks! Just tried this and it's looking the same – the anchor link only appears on the first section, none of the others have any anchors appearing. Link to comment
Beyondspace Posted September 18, 2022 Share Posted September 18, 2022 10 hours ago, joaquins said: @bangank36 Thanks! Just tried this and it's looking the same – the anchor link only appears on the first section, none of the others have any anchors appearing. Can you share your site with the protected password so I can take a look? BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox, video lightbox and much more) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace (+100 Spark plugin customisations) 🥳 Freemium Squarespace Widget Templates (+1000 Elfsight Templates) If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment