[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
This commit is contained in:
@@ -15,7 +15,7 @@ publicWidget.registry.affixMenu = publicWidget.Widget.extend({
|
||||
var def = this._super.apply(this, arguments);
|
||||
|
||||
var self = this;
|
||||
this.$headerClone = this.$target.clone().addClass('o_header_affix affix').removeClass('o_affix_enabled').removeAttr('id');
|
||||
this.$headerClone = this.$target.clone().addClass('o_header_affix affix o_top_fixed_element').removeClass('o_affix_enabled').removeAttr('id');
|
||||
this.$headerClone.insertAfter(this.$target);
|
||||
this.$headers = this.$target.add(this.$headerClone);
|
||||
this.$dropdowns = this.$headers.find('.dropdown');
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<t t-set="body_classname" t-value="(body_classname if body_classname else '') + (' o_connected_user' if env['ir.ui.view'].user_has_groups('base.group_user') else '')"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='wrapwrap']" position="before">
|
||||
<nav groups="base.group_user" t-if="website and menu_data" id="oe_main_menu_navbar" class="o_main_navbar">
|
||||
<nav groups="base.group_user" t-if="website and menu_data" id="oe_main_menu_navbar" class="o_main_navbar o_top_fixed_element">
|
||||
<ul id="oe_applications">
|
||||
<li class="dropdown active">
|
||||
<a class="dropdown-toggle full" data-toggle="dropdown" href="#">
|
||||
|
||||
Reference in New Issue
Block a user