10 examples of 'cypress scrollintoview' in JavaScript

Every line of 'cypress scrollintoview' 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
1export default function scrollIntoView(element) {
2 const scroller = getScrollParent(element);
3
4 if (!scroller) {
5 return;
6 }
7
8 const scroll = scroller.scrollTop;
9 const elementTop = getOffset(element).top;
10 const scrollerTop = getOffset(scroller).top;
11 const elementBottom = elementTop + element.offsetHeight;
12 const scrollerBottom = scrollerTop + scroller.clientHeight;
13 const outOfBoundsTop = elementTop - scrollerTop < 0;
14 const outOfBoundsBottom = elementBottom > scrollerBottom;
15
16 if (outOfBoundsTop) {
17 scroller.scrollTop = scroll + (elementTop - scrollerTop);
18 } else if (outOfBoundsBottom) {
19 scroller.scrollTop = scroll + (elementBottom - scrollerBottom);
20 }
21}
173function scrollIntoView(node)
174{
175 var scroll = getVerticalScroll(node);
176 if (scroll != 0)
177 window.scrollBy(0, scroll);
178}
5function scrollIntoView (element) {
6 if (element){
7 const scrollY = element.getBoundingClientRect().top + (window.scrollY || window.pageYOffset);
8 window.scroll({ top: scrollY, left: 0, behavior: 'smooth' });
9 }
10}
12function scrollIntoView(container, selected) {
13 if (_vue2.default.prototype.$isServer) return;
14
15 if (!selected) {
16 container.scrollTop = 0;
17 return;
18 }
19
20 var offsetParents = [];
21 var pointer = selected.offsetParent;
22 while (pointer && container !== pointer && container.contains(pointer)) {
23 offsetParents.push(pointer);
24 pointer = pointer.offsetParent;
25 }
26 var top = selected.offsetTop + offsetParents.reduce(function (prev, curr) {
27 return prev + curr.offsetTop;
28 }, 0);
29 var bottom = top + selected.offsetHeight;
30 var viewRectTop = container.scrollTop;
31 var viewRectBottom = viewRectTop + container.clientHeight;
32
33 if (top < viewRectTop) {
34 container.scrollTop = top;
35 } else if (bottom > viewRectBottom) {
36 container.scrollTop = bottom - container.clientHeight;
37 }
38}
78function scrollIntoView(element) {
79 var viewportTop = (document.body.scrollTop +
80 document.documentElement.scrollTop);
81 var viewportHeight = window.innerHeight;
82 var elementBox = element.getBoundingClientRect();
83 var pixelsToOverlap = elementBox.bottom - elementBox.top + 8;
84
85 var scrollTo;
86 if (elementBox.top < 0) {
87 scrollTo = viewportTop +
88 pixelsToOverlap + elementBox.bottom - viewportHeight;
89 } else if (elementBox.bottom > viewportHeight) {
90 scrollTo = viewportTop + elementBox.top - pixelsToOverlap;
91 } else {
92 return;
93 }
94
95 scrollTo = Math.min(document.body.scrollHeight - viewportHeight,
96 Math.max(0, scrollTo));
97 window.scroll(document.body.scrollLeft +
98 document.documentElement.scrollLeft,
99 scrollTo);
100}
72scrollIntoView (element: HTMLElement) {
73 if (!this._container) {
74 throw new Error('A container must be set on the scroller with `scroller.setContainer(container)` before trying to scroll an element into view')
75 }
76
77 if (this._isFullyVisible(element)) {
78 return
79 }
80
81 // aim to scroll just into view, so that the bottom of the element
82 // is just above the bottom of the container
83 let scrollTopGoal = this._aboveBottom(element)
84
85 // can't have a negative scroll, so put it to the top
86 if (scrollTopGoal < 0) {
87 scrollTopGoal = 0
88 }
89
90 this._userScroll = false
91 this._container.scrollTop = scrollTopGoal
92}
334function isScrollIntoView(scroll = true) {
335 const { hash } = window.location;
336 if (hash) {
337 var el = document.querySelector(`${hash}>details`);
338 if (el) {
339 el.open = true;
340 if (scroll) el.scrollIntoView({ behavior: 'smooth' });
341 }
342 }
343}
12ngOnChanges(changes: SimpleChanges) {
13 if (this.condition) {
14 setTimeout(() => {
15 this.scrollIntoViewService.scrollIntoView(this.element.nativeElement, this.scrollParent);
16 });
17 }
18}
277scrollIntoView(scrollingContainer) {
278 const range = this.lastRange;
279 if (range == null) return;
280 const bounds = this.getBounds(range.index, range.length);
281 if (bounds == null) return;
282 const limit = this.scroll.length() - 1;
283 const [first] = this.scroll.line(Math.min(range.index, limit));
284 let last = first;
285 if (range.length > 0) {
286 [last] = this.scroll.line(Math.min(range.index + range.length, limit));
287 }
288 if (first == null || last == null) return;
289 const scrollBounds = scrollingContainer.getBoundingClientRect();
290 if (bounds.top < scrollBounds.top) {
291 scrollingContainer.scrollTop -= scrollBounds.top - bounds.top;
292 } else if (bounds.bottom > scrollBounds.bottom) {
293 scrollingContainer.scrollTop += bounds.bottom - scrollBounds.bottom;
294 }
295}
53get scrollingElement() {
54 return document.querySelector('[data-component="Content"]');
55}

Related snippets