Hello guys , I have a question that is with in the template.
Where can i create a button that directly scrolls down to an image inside the template.
To create an anchor link to something that is on the same page you have to add an id to the element you want to scroll to, then change the href of the button to that id e.g. <img id=“anchorimage” src=“…”> and <a href=“#anchorimage”> (using an anchor <a> element and styling it as a button is easier than using a <button> element which doesn’t have an href attribute).
Hey @Sergelen
To piggyback on @piersg 's answer:
If you would like a scroll animtion to take place you could use something like this (assuming you switch to a anchor tag):
$(document).on('click', function(e) {
if ( e.target.hash.indexOf('#') == 0 ) {
e.preventDefault();
var link = e.target.hash;
$([document.documentElement, document.body]).animate({
scrollTop: $(link).offset().top
}, 'fast');
}
});
This script fires when the user clicks a link that has a “#” as the first character, then scrolls to that anchor.
@Kevin-C you can also do this with scroll-behaviour property
html {
scroll-behavior: smooth;
}
@piersg YES! much more elegant!
+1 to the scroll-behavior, but remember that not all browsers support it. I am lookinig at you, safari and IE!