summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/content/snippets.animation.js
diff options
context:
space:
mode:
authorBenjamin Vray <bvr@odoo.com>2019-12-18 11:36:59 +0000
committerqsm-odoo <qsm@odoo.com>2020-01-30 16:55:31 +0000
commit8d3d32ec4490cf72b4057cbd91247e5cc8e174be (patch)
tree6c9ad782cd509b64d6b7823fa6113144d25c28cf /addons/website/static/src/js/content/snippets.animation.js
parentf61b4669a9607c3cb800d5ec33ab0001086f2d97 (diff)
[IMP] website: set anchor offset by fixed header height
When you click on an anchor link, this commit ensures that the scroll is in the correct place if there are fixed menus on the page. Part of https://github.com/odoo/odoo/pull/40690 task-1894456
Diffstat (limited to 'addons/website/static/src/js/content/snippets.animation.js')
-rw-r--r--addons/website/static/src/js/content/snippets.animation.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js
index a4c82cfe2de..e0cf1df3fcd 100644
--- a/addons/website/static/src/js/content/snippets.animation.js
+++ b/addons/website/static/src/js/content/snippets.animation.js
@@ -908,11 +908,22 @@ registry.anchorSlide = publicWidget.Widget.extend({
/**
* @private
* @param {jQuery} $el the element to scroll to.
+ * @param {string} [scrollValue='true'] scroll value
*/
- _scrollTo: function ($el) {
+ _scrollTo: function ($el, scrollValue = 'true') {
+ const headerHeight = this._computeHeaderHeight();
$('html, body').animate({
- scrollTop: $el.offset().top,
- }, 500);
+ scrollTop: $el.offset().top - headerHeight,
+ }, scrollValue === 'true' ? 500 : 0);
+ },
+ /**
+ * @private
+ */
+ _computeHeaderHeight: function () {
+ let headerHeight = 0;
+ const $navbarFixed = $('.o_top_fixed_element');
+ _.each($navbarFixed, el => headerHeight += $(el).outerHeight());
+ return headerHeight;
},
//--------------------------------------------------------------------------
@@ -931,11 +942,12 @@ registry.anchorSlide = publicWidget.Widget.extend({
return;
}
var $anchor = $(hash);
- if (!$anchor.length || !$anchor.attr('data-anchor')) {
+ const scrollValue = $anchor.attr('data-anchor');
+ if (!$anchor.length || !scrollValue) {
return;
}
ev.preventDefault();
- this._scrollTo($anchor);
+ this._scrollTo($anchor, scrollValue);
},
});