The difference between the decision on pure JS and jQuery in this matter is not significant. All the differences are in fact in search of DOM elements and dimensions.
To remake the decision on pure JS, simply use the resource: youmightnotneedjquery.com
PS Why invent when there is stickyjs.com
and generally Packed www.hongkiat.com/blog/sticky-elements-jquery-plugins