Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollintoview animation

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.nodeValue == now) {                 // 'ffff99' // '#ffd700' // TODAY - red                 rows[i].style.backgroundColor = 'red'                  rows[i].scrollIntoView();             }         }     } } 

I need to find a way to smooth the .scrollintoview(). Right now it 'jumps' to the highlighted row. I need it to smoothly transition to that row. It needs to be done dynamically in replacement of scrollintoview. Any ideas? Thanks.

like image 824
Ted Lederer Avatar asked Aug 24 '12 01:08

Ted Lederer


People also ask

When should I use scrollIntoView?

The scrollIntoView() method scrolls an element into the visible area of the browser window.

How do I make my scrollIntoView smooth?

Native method: scrollIntoView The usage is simple, just like this: function scroll(e) {e. scrollIntoView({behavior: "smooth", block: "start"});}scroll(document. getElementById(YOUR_DIV_ID));

Can I use scrollIntoView?

scrollIntoView on Android Browser is fully supported on 97-103, partially supported on 2.3-4, and not supported on below 2.3 Android Browser versions. scrollIntoView on Opera Mobile is fully supported on 64-64, partially supported on 10-12, and not supported on below 10 Opera Mobile versions.

Does scrollIntoView work horizontally?

scrollIntoView(true);", element); This works for vertical scrolling but not for horizontal.


1 Answers

In most modern browsers (Chrome and Firefox, but not Safari, UC, or IE) you can pass options in an object to .scrollIntoView().

Try this:

elm.scrollIntoView({ behavior: 'smooth', block: 'center' }) 

Other values are behavior: 'instant' or block: 'start' or block: 'end'. See https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView

like image 187
Chris78 Avatar answered Sep 20 '22 17:09

Chris78