Anchor tag and jQuery Scroll to View

Опубликовано: 16 Июнь 2026
на канале: Cyane Tornatzky
17
0

Here we go over the anchor tag and start using some jQuery. YouTube doesn't allow for brackets in the comments, so I'm verbally describing what what you should do.

This is from Edvard Åkerberg on Stack Overflow

Put this in your head tag (before your closing head tag)

caret script then:
src="https://cdnjs.cloudflare.com/ajax/lib..."
caret

caret forward slash caret


Put this code right above your closing html tag

Open up your script tag:
caret script caret
function scrollTo(selector) {
document.querySelector(selector).scrollTop({ behavior: 'smooth' })
}

$(".butterfly").click(function() {
document.getElementById("spider").scrollIntoView( {behavior: "smooth" })
})
close your script tag: caret forward slash script caret