我正在使用this script來顯示和隱藏模式視圖,但是我希望在打開模式視圖時禁用滾動,並在關閉模式視圖時禁用它。在疊加模式視圖中禁用滾動身體
我試圖修改JS代碼,但它的作品,但它打破了開場動畫。這裏是修改了代碼:
(function() {
var triggerBttn = document.getElementById('trigger-overlay'),
overlay = document.querySelector('div.overlay'),
bodyTag = document.querySelector('body'),
closeBttn = overlay.querySelector('button.overlay-close');
transEndEventNames = {
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition': 'transitionend',
'OTransition': 'oTransitionEnd',
'msTransition': 'MSTransitionEnd',
'transition': 'transitionend'
},
transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ],
support = { transitions : Modernizr.csstransitions };
function toggleOverlay() {
if(classie.has(overlay, 'open')) {
classie.remove(overlay, 'open');
classie.add(overlay, 'close');
var onEndTransitionFn = function(ev) {
if(support.transitions) {
if(ev.propertyName !== 'visibility') return;
this.removeEventListener(transEndEventName, onEndTransitionFn);
}
classie.remove(overlay, 'close');
classie.remove(bodyTag, 'noscroll');
};
if(support.transitions) {
overlay.addEventListener(transEndEventName, onEndTransitionFn);
}
else {
onEndTransitionFn();
}
}
else if(!classie.has(overlay, 'close')) {
classie.add(overlay, 'open');
classie.add(bodyTag, 'noscroll');
}
}
triggerBttn.addEventListener('click', toggleOverlay);
closeBttn.addEventListener('click', toggleOverlay);})();
原始演示:jsfiddle
如果你看看我的代碼,你會發現我試圖實現這個解決方案,但正如我提到它不工作,它打破了動畫 – Dev4life