網路上的範例大多以body為容器,稍微修改了一下以適應在其他DOM內的scrolling效果:
/**
* @param target a jQuery selector string, target DOM; or scrollTop value
* @param container a jQuery selector string, represents DOM which contains target, default is 'html, body'
*/
function smoothScrollTo(target, container) {
container = container ? container : 'html, body';
$(container).animate({
scrollTop: $.isNumeric(target) ?
target :
$(target).offset().top
+ $(container).scrollTop()
- $(container).offset().top
}, 300);
}
// Ex: smoothScrollTo('#anchor');
Anchor 1
This page is made to demonstrate what i learned from some popular javascript library/framework. For now, it used H5BP as basic template, Bootstrap for layout and CSS style, and jQuery. (Backbone.js is going to be added for MVC implemenation)
Anchor 2
This page is made to demonstrate what i learned from some popular javascript library/framework. For now, it used H5BP as basic template, Bootstrap for layout and CSS style, and jQuery. (Backbone.js is going to be added for MVC implemenation)
Anchor 3
This page is made to demonstrate what i learned from some popular javascript library/framework. For now, it used H5BP as basic template, Bootstrap for layout and CSS style, and jQuery. (Backbone.js is going to be added for MVC implemenation)