js-scrollintoview

Using document.querySelector in React? Should I use refs instead? How?

谁说胖子不能爱 提交于 2021-02-18 05:15:19
问题 I am building a carousel right now, in React. To scroll to the individual slides I am using document.querySelector like so : useEffect(() => { document.querySelector(`#slide-${activeSlide}`).scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' }); }, [activeSlide]); Is this bad practice? After all, I am accessing the DOM directly here? What would be the React way of doing this? edit: full return method return ( <> <button onClick={() => setActiveSlide(moveLeft)}>PREV<

Using document.querySelector in React? Should I use refs instead? How?

余生长醉 提交于 2021-02-18 05:15:18
问题 I am building a carousel right now, in React. To scroll to the individual slides I am using document.querySelector like so : useEffect(() => { document.querySelector(`#slide-${activeSlide}`).scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' }); }, [activeSlide]); Is this bad practice? After all, I am accessing the DOM directly here? What would be the React way of doing this? edit: full return method return ( <> <button onClick={() => setActiveSlide(moveLeft)}>PREV<

Google Chrome: Simultaneously 'smooth' scrollIntoView() with more elements doesn't work

眉间皱痕 提交于 2021-02-17 19:07:31
问题 In Google Chrome, element.scrollIntoView() with behavior: 'smooth' doesn't work on multiple containers at the same time. As soon as smooth scrolling is triggered on one container, the second container stops scrolling. In Firefox, this problem doesn’t exist; both containers can scroll simultaneously. My workaround is using behavior: 'instant' , but I like to use behavior: 'smooth' for a better user experience. Example Here is a plunker using Angular html <p> In Google Chrome element

Lazy Loading and ScrollIntoView() Angular2(version 7)

梦想的初衷 提交于 2021-02-11 12:49:00
问题 I'm trying to show a component when first load the page with lazy loading that only load the content if it's in the view. For example: - There are 10 components on the page and I want to show/scroll to the component number 7 on first load with lazy loading(for performance). How do I do this correctly? Challenge here is because these components are lazy loading and have huge images that messed up the scrollIntoView() and scrolled too much to the top passed the component. I've tried these

How to know scroll to element is done in Javascript?

时间秒杀一切 提交于 2019-12-28 02:06:28
问题 I am using Javascript method Element.scrollIntoView() https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView Is there any way I can get to know when the scroll is over. Say there was an animation, or I have set {behavior: smooth} . I am assuming scrolling is async and want to know if there is any callback like mechanism to it. 回答1: You can use IntersectionObserver, check if element .isIntersecting at IntersectionObserver callback function const element = document

Calling scrollIntoView(…) with block center not working

断了今生、忘了曾经 提交于 2019-12-11 07:38:23
问题 I'm trying to get the following code to work but it doesn't: $.each($("input, select"), function (index, input) { input.addEventListener("invalid", function () { this.scrollIntoView({ behavior: 'smooth', block: 'center' }); }); }); What this says is: for each input and select in my form, add an event listener that listens for the "invalid" state (fired upon submitting the form if any of the inputs or selects are invalid). The event listener will scroll the input or select into view at the

Javascript scrollIntoView() middle alignment?

笑着哭i 提交于 2019-11-28 17:22:54
Javascript .scrollIntoView(boolean) provide only two alignment option. top bottom What if I want to scroll the view such that. I want to bring particular element somewhere in middle of the page? Use window.scrollTo() for this. Get the top of the element you want to move to, and subtract one half the window height. Demo: http://jsfiddle.net/ThinkingStiff/MJ69d/ Element.prototype.documentOffsetTop = function () { return this.offsetTop + ( this.offsetParent ? this.offsetParent.documentOffsetTop() : 0 ); }; var top = document.getElementById( 'middle' ).documentOffsetTop() - ( window.innerHeight /

scrollintoview animation

岁酱吖の 提交于 2019-11-27 19:20:17
My code is at http://jsfiddle.net/mannagod/QT3v5/7/ . The JS is: function delay() { var INTENDED_MONTH = 7 //August // INTENDED_MONTH is zero-relative now = new Date().getDate(), rows = document.getElementById('scripture').rows; if (new Date().getMonth() != INTENDED_MONTH) { // need a value here less than 1, // or the box for the first of the month will be in Red now = 0.5 }; for (var i = 0, rl = rows.length; i < rl; i++) { var cells = rows[i].childNodes; for (j = 0, cl = cells.length; j < cl; j++) { if (cells[j].nodeName == 'TD' && cells[j].firstChild.nodeValue != '' && cells[j].firstChild

Javascript scrollIntoView() middle alignment?

試著忘記壹切 提交于 2019-11-27 10:25:59
问题 Javascript .scrollIntoView(boolean) provide only two alignment option. top bottom What if I want to scroll the view such that. I want to bring particular element somewhere in middle of the page? 回答1: Use window.scrollTo() for this. Get the top of the element you want to move to, and subtract one half the window height. Demo: http://jsfiddle.net/ThinkingStiff/MJ69d/ Element.prototype.documentOffsetTop = function () { return this.offsetTop + ( this.offsetParent ? this.offsetParent