Focus management of smooth scrolling

Developer
Size
2,506 Kb
Views
40,480

How do I make an focus management of smooth scrolling?

What is a focus management of smooth scrolling? How do you make a focus management of smooth scrolling? This script and codes were developed by Heydon on 27 August 2022, Saturday.

Focus management of smooth scrolling Previews

Focus management of smooth scrolling - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Focus management of smooth scrolling</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <nav role="navigation"> <ul> <li><a href="#section1">Section 1</a></li> <li><a href="#section2">Section 2</a></li> <li><a href="#section3">Section 3</a></li> </ul>
</nav>
<section id="section1"> <h2>Section 1</h2> <p>Donec tempus tempus tellus, ac lacinia turpis mattis ac. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh. Donec tempus tempus tellus, ac lacinia turpis mattis ac. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh. Donec tempus tempus tellus, ac lacinia turpis mattis ac. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh.</p>
</section>
<section id="section2"> <h2>Section 2</h2> <p>Maecenas sit amet tellus &ndash; nec mi gravida posuere non <a href="#">pretium magna</a>. Potenti et eros sed justo commodo bibendum non at nunc. Suspendisse potenti cras molestie, risus a enim convallis vitae luctus libero lacinia. Donec tempus tempus tellus, ac lacinia turpis mattis ac. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh. Donec tempus tempus tellus, ac lacinia turpis mattis ac. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh. Donec tempus tempus tellus, ac lacinia turpis mattis ac. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh.</p>
</section>
<section id="section3"> <h2>Section 3</h2> <p>Donec a congue leo. Suspendisse potenti cras molestie, risus a enim convallis vitae luctus libero lacinia. Nunc iaculis risus vel orci ornare dignissim sed vitae nulla.</p>
</section> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Focus management of smooth scrolling - Script Codes CSS Codes

body { max-width: 30em; padding: 1.5em 0; margin: 0 auto; font-size: 150%;
}
nav li { display: inline; padding-right: 1em;
}
ul { margin: 0; padding: 0;
}
a { color: blue;
}

Focus management of smooth scrolling - Script Codes JS Codes

/* Basics lifted from a CSS Tricks demo (http://css-tricks.com/snippets/jquery/smooth-scrolling/), with focus() and URL hash updating added where commented */
$(function() { /* ADDED: make sections focusable */ $('section[id]').attr('tabindex', '-1'); /* end ADDED */ $('a[href*=#]:not([href=#])').on('click', function(e) { var $linkElem = $(this); if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { e.preventDefault(); var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top }, 1000, function() { target.focus(); window.location.hash = $linkElem.attr('href').substring(1); }); } } });
});
Focus management of smooth scrolling - Script Codes
Focus management of smooth scrolling - Script Codes
Home Page Home
Developer Heydon
Username heydon
Uploaded August 27, 2022
Rating 3
Size 2,506 Kb
Views 40,480
Do you need developer help for Focus management of smooth scrolling?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Heydon (heydon) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!