mirror of
https://github.com/odoo/design-themes.git
synced 2025-10-07 01:18:52 +07:00
[IMP] website_animate: hide horizontal scrollbar during animation
Before this commit, when animated elements with a css translate
overflowed the #wrapwrap (before and during animations), a horizontal
scrollbar was visible on the #wrapwrap until the end of the animation.
After this commit, the horizontal scrollbar is no longer visible at
any time during the animations.
task-2215118
closes odoo/design-themes#471
X-original-commit: 22e83be4f3
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -5,12 +5,19 @@ var sOptions = require('web_editor.snippets.options');
|
|||||||
|
|
||||||
function forceAnimation() {
|
function forceAnimation() {
|
||||||
var $els = $();
|
var $els = $();
|
||||||
|
const $scrollingElement = $().getScrollingElement();
|
||||||
_.each(arguments, function (el) {
|
_.each(arguments, function (el) {
|
||||||
$els = $els.add(el);
|
$els = $els.add(el);
|
||||||
});
|
});
|
||||||
$els.css('animation-name', 'dummy');
|
$els.css('animation-name', 'dummy');
|
||||||
void $els[0].offsetWidth;
|
void $els[0].offsetWidth;
|
||||||
|
$els.addClass('o_animating');
|
||||||
|
$scrollingElement[0].classList.add('o_wanim_overflow_x_hidden');
|
||||||
$els.css('animation-name', '');
|
$els.css('animation-name', '');
|
||||||
|
$els.one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) {
|
||||||
|
$scrollingElement[0].classList.remove('o_wanim_overflow_x_hidden');
|
||||||
|
$els.removeClass('o_animating');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animations
|
// Animations
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ var WebsiteAnimate = {
|
|||||||
// Retrieve animable elements and attach handlers.
|
// Retrieve animable elements and attach handlers.
|
||||||
start: function () {
|
start: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
self.$scrollingElement = $().getScrollingElement();
|
||||||
self.items = $(".o_animate");
|
self.items = $(".o_animate");
|
||||||
self.items.each(function () {
|
self.items.each(function () {
|
||||||
var $el = $(this);
|
var $el = $(this);
|
||||||
@@ -36,7 +37,7 @@ var WebsiteAnimate = {
|
|||||||
})
|
})
|
||||||
.trigger("resize");
|
.trigger("resize");
|
||||||
|
|
||||||
$().getScrollingElement()
|
self.$scrollingElement
|
||||||
.on("scroll.o_animate, slid.bs.carousel", (_.throttle(function () {
|
.on("scroll.o_animate, slid.bs.carousel", (_.throttle(function () {
|
||||||
// _.throttle -> Limit the number of times the scroll function
|
// _.throttle -> Limit the number of times the scroll function
|
||||||
// can be called in a given period. (http://underscorejs.org/#throttle)
|
// can be called in a given period. (http://underscorejs.org/#throttle)
|
||||||
@@ -73,12 +74,15 @@ var WebsiteAnimate = {
|
|||||||
|
|
||||||
// Set elements to initial state
|
// Set elements to initial state
|
||||||
reset_animation: function ($el) {
|
reset_animation: function ($el) {
|
||||||
|
var self = this;
|
||||||
var anim_name = $el.css("animation-name");
|
var anim_name = $el.css("animation-name");
|
||||||
|
|
||||||
$el
|
$el
|
||||||
.css({"animation-name" : "dummy-none", "animation-play-state" : ""})
|
.css({"animation-name" : "dummy-none", "animation-play-state" : ""})
|
||||||
.removeClass("o_animated o_animating");
|
.removeClass("o_animated o_animating");
|
||||||
|
|
||||||
|
self._toggleOverflowXHidden(false);
|
||||||
|
|
||||||
// force the browser to redraw using setTimeout
|
// force the browser to redraw using setTimeout
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$el.css({"animation-name" : anim_name, "animation-play-state" : "paused"});
|
$el.css({"animation-name" : anim_name, "animation-play-state" : "paused"});
|
||||||
@@ -87,18 +91,30 @@ var WebsiteAnimate = {
|
|||||||
|
|
||||||
// Start animation and/or update element's state
|
// Start animation and/or update element's state
|
||||||
start_animation: function ($el) {
|
start_animation: function ($el) {
|
||||||
|
var self = this;
|
||||||
// force the browser to redraw using setTimeout
|
// force the browser to redraw using setTimeout
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
self._toggleOverflowXHidden(true);
|
||||||
$el
|
$el
|
||||||
.css({"animation-play-state": "running"})
|
.css({"animation-play-state": "running"})
|
||||||
.addClass("o_animating")
|
.addClass("o_animating")
|
||||||
.one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) {
|
.one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) {
|
||||||
$el.addClass("o_animated").removeClass("o_animating");
|
$el.addClass("o_animated").removeClass("o_animating");
|
||||||
|
self._toggleOverflowXHidden(false);
|
||||||
$(window).trigger("resize");
|
$(window).trigger("resize");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// show/hide the horizontal scrollbar (on the #wrapwrap)
|
||||||
|
_toggleOverflowXHidden: function (add) {
|
||||||
|
if (add) {
|
||||||
|
this.$scrollingElement[0].classList.add('o_wanim_overflow_x_hidden');
|
||||||
|
} else if (!this.$scrollingElement.find('.o_animating').length) {
|
||||||
|
this.$scrollingElement[0].classList.remove('o_wanim_overflow_x_hidden');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Get element top offset by not taking CSS transforms into calculations
|
// Get element top offset by not taking CSS transforms into calculations
|
||||||
getElementOffsetTop: function (el) {
|
getElementOffsetTop: function (el) {
|
||||||
// Loop through the DOM tree and add its parent's offset to get page offset
|
// Loop through the DOM tree and add its parent's offset to get page offset
|
||||||
@@ -128,6 +144,13 @@ publicWidget.registry.WebsiteAnimate = publicWidget.Widget.extend({
|
|||||||
|
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
destroy: function () {
|
||||||
|
WebsiteAnimate.$scrollingElement[0].classList.remove('o_wanim_overflow_x_hidden');
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Backward compatibility for enark animation system
|
// Backward compatibility for enark animation system
|
||||||
|
|||||||
@@ -10,10 +10,17 @@
|
|||||||
backface-visibility: hidden; // avoid flickering
|
backface-visibility: hidden; // avoid flickering
|
||||||
text-rendering: geometricPrecision; // take care of animated titles
|
text-rendering: geometricPrecision; // take care of animated titles
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
|
|
||||||
|
&:not(.o_animating) {
|
||||||
|
transform: none !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.o_animate_preview {
|
.o_animate_preview {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
}
|
}
|
||||||
|
.o_wanim_overflow_x_hidden {
|
||||||
|
overflow-x: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
@-moz-keyframes o_animate_timeline_duration {
|
@-moz-keyframes o_animate_timeline_duration {
|
||||||
0% { width: 0; }
|
0% { width: 0; }
|
||||||
|
|||||||
Reference in New Issue
Block a user