Barba.jsでアニメーションが終了してから body の class を更新しようとしているのですが可能でしょうか。
body の class からCSSを引っ張ってきているのでできるならばしたいのですが。
(WordPress の jQuery を使用しています。)
javascript
1Barba.Dispatcher.on('newPageReady', function (currentStatus, oldStatus, container, newPageRawHTML) { 2 let regexp = /\<body.*\sclass=["'](.+?)["'].*\>/gi, match = regexp.exec(newPageRawHTML); 3 if (!match || !match[1]) return; 4 document.body.setAttribute('class', match[1]); 5}); 6 7var FadeTransition = Barba.BaseTransition.extend({ 8 start: function () { 9 Promise 10 .all([this.newContainerLoading, this.fadeOut()]) 11 .then(this.fadeIn.bind(this)); 12 }, 13 14 fadeOut: function () { 15 return jQuery(this.oldContainer).animate({ opacity: 0 }).promise(); 16 }, 17 18 fadeIn: function () { 19 var _this = this; 20 var $el = jQuery(this.newContainer); 21 22 jQuery(this.oldContainer).hide(); 23 24 $el.css({ 25 visibility: 'visible', 26 opacity: 0 27 }); 28 29 $el.animate({ opacity: 1 }, 300, function () { 30 _this.done(); 31 }); 32 } 33}); 34 35Barba.Pjax.getTransition = function () { 36 return FadeTransition; 37}; 38 39Barba.Pjax.start();
プラグイン/ライブラリは公式配布サイトのURLを質問文に追記ください。(URLにはリンクを張ることができます)
あなたの回答
tips
プレビュー