Tip: Click lines to highlight, hold ctrl/cmd to multi-select
scrollIntoView method JavaScript (13-Nov @ 11:57)
scrolls to an element if it is not visible
Syntax Highlighted Code
- var targetOffset = jQuery(target).offset().top;
- var containerOffset = jQuery('#productsDiv').offset().top;
- if(targetOffset < containerOffset) {
- target.scrollIntoView();
- }
Plain Code
var targetOffset = jQuery(target).offset().top;
var containerOffset = jQuery('#productsDiv').offset().top;
if(targetOffset < containerOffset) {
target.scrollIntoView();
}