How the code works scrolling?

$(function() {$('body').on('click', 'a.scrollable', function(event) {
 var $anchor = $(this);
 $('html, body').stop().animate({scrollTop: $($anchor.attr('href')).offset().top},1500,'easeInOutExpo');

Preferably an explanation on the lines. In particular it is not clear that var $anchor = $(this);
and this $('html, body').stop().animate
July 2nd 19 at 13:51
2 answers
July 2nd 19 at 13:53
$(function() {$('body').on('click', 'a.scrollable', function(event) {
//so is the click event on the link to make it work for dynamically created elements which are not yet on the page. Instead of a bodysuit can be any parent who will be on the page always.
 var $anchor = $(this); //this is the element which triggered click event
 $('html, body').stop()//stop all animations
.animate( //animation effect
{scrollTop: //will animate scrolling
$($anchor.attr('href'))//get the href attribute of the element, it will be the same block where to prosquality. $("#elem") - so get
.offset().top //distance from start page to
},1500 //time of animation
,'easeInOutExpo'// dynamics animation
 event.preventDefault(); //cancel the link browser

Do not tell me why the anchor icon dollar is worth? - Adriel commented on July 2nd 19 at 13:56
Dream about books, or collections of code here with such detailed explanations) Thanks - Adriel commented on July 2nd 19 at 13:59
So I decided to call variables that contain collections of elements
$elements = $(".elem");
$elements.enyFunction() and so on
Nothing to do with PHP - Jeremy_Kulas commented on July 2nd 19 at 14:02
July 2nd 19 at 13:55
here to you the basics of js helped, well, just very, to clarify there is essentially nothing...

var $anchor = $(this); in this case, this is a.scrollable, it is used essentially for obtaining a value of the href attribute of the link on which I clicked.
stop(). Stops the currently running animation.
animate animates...
Yes, I know the basics of js. Got me baffled is stop(), as like in the example no animations to stop. Don't know what to do so. And what is this know. But the variable c $ is the first. - Adriel commented on July 2nd 19 at 13:58
variables with $ are written in php , just a habit of those people that write it, nothing more, in this case, $ is just a symbol, he is no different from "a" or "b".

.stop() is used as reassurance, for example if you click quickly the link from the example a couple of times the animation will be all these a few times, to avoid this and use stop

To learn the basics of js, was said in offense, just faster all will understand. It's really the basics, especially the part with the symbol $ . - Adriel commented on July 2nd 19 at 14:01

Find more questions by tags JavaScriptjQuery