10 examples of 'js scroll to element' in JavaScript

Every line of 'js scroll to element' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
3function scroll () {
4 if (window.location.hash === '') return
5 const anchor = $j('a[href="' + window.location.hash + '"]')
6 if (anchor) $j(window).scrollTop(anchor.offset().top)
7}
36function scroll_to(delta) {
37
38 if (delta < 0 ) {
39
40 delta = -scrollinc;
41 } else {
42
43 delta = scrollinc;
44 }
45
46 delta = delta * deltaKoef;
47
48 var listWidth = scroller.find('.dslca-section-scroller-content').width();
49 var contentWidth = scroller.width();
50
51 if ( listWidth <= contentWidth ) return false;
52
53 var scrollMax = listWidth - contentWidth + 10;
54
55 delta = parseInt(scrollInner.style.left || 0) - delta;
56 delta = delta >= 0 ? 0 : delta;
57 delta = delta <= -scrollMax ? -scrollMax : delta;
58
59 scrollInner.style.left = delta + 'px';
60}
120_scroll(x, y, callback) {
121 // Guarantees:
122 // - x: number
123 // - y: number
124 // => callback(err)
125}
65scroll(v) {
66 const {el} = this;
67 if (v !== undefined) {
68 if (v.left !== undefined) {
69 el.scrollLeft = v.left;
70 }
71 if (v.top !== undefined) {
72 el.scrollTop = v.top;
73 }
74 }
75
76 return {left: el.scrollLeft, top: el.scrollTop};
77}
62scroll(v) {
63 const { el } = this;
64 if (v !== undefined) {
65 if (v.left !== undefined) {
66 el.scrollLeft = v.left;
67 }
68 if (v.top !== undefined) {
69 el.scrollTop = v.top;
70 }
71 }
72 return { left: el.scrollLeft, top: el.scrollTop };
73}
234export function scroll(data: ScrollData, iframe: HTMLIFrameElement): void {
235 let target = getNode(data.target);
236 if (target) { target.scrollTo(data.x, data.y); }
237}
97function scrollElement(element: Element, x: number, y: number) {
98 element.scrollLeft = x;
99 element.scrollTop = y;
100}
209scroll(offset=0, line=null) {
210 let start_div = document.getElementById(`input-start-${this.uuid}`)
211 let start_ypos = scroll_position(start_div, offset)
212
213 let end_div = document.getElementById(`input-end-${this.uuid}`)
214 let end_ypos = scroll_position(end_div, offset)
215
216 // TODO: Filter out lines containing whitespace only
217 let delta = (start_ypos - end_ypos) / this.source.split("\n").length
218 let ypos = ((this.mode == 'code') && (line==null)) ? (start_ypos + delta) : start_ypos
219 let line_offset = (line != null) ? (delta*line) : 0
220 window.scroll({top : ypos - line_offset + offset,
221 left : 0, behavior : 'smooth'})
222}
37function doScroll() {
38 var scroll = $(window).scrollTop();
39 var windowHeight = $(window).height();
40 var documentHeight = $(document).height();
41
42 var heightLessScroll = (documentHeight - windowHeight) - scroll;
43
44 if (heightLessScroll <= MINIMUM_HEIGHT_FOR_TO_LOAD) {
45 // $('.show-more').trigger('click');
46 }
47}
73function scrollToElement(element) {
74
75 if (isElementInView(element)) {
76 return;
77 }
78
79 try {
80 element.scrollIntoView({
81 behavior: "smooth"
82 });
83 }
84 catch (error) {
85 console.error(error);
86 }
87}

Related snippets