天天看點

html下移屬性設定,css下移動畫該怎麼實作呢?

寫了個 demo ,希望對你有用。

Document

html,

body {

margin: 0;

padding: 0;

background: #333;

}

.popup {

width: 100%;

top: auto;

right: auto;

bottom: 0;

left: 50%;

position: fixed;

background: #fff;

top: 50%;

left: 50%;

backface-visibility: hidden;

transition: .2s ease-out;

transform: translate3d(-50%, 100%, 0);

}

顯示/隐藏

嘻嘻嘻嘻嘻

const button = document.querySelector('button'),

popup = document.querySelector('.popup');

let show = true

button.addEventListener('click', function() {

if (show) {

popup.style.transform = 'translate3d(-50%, 0, 0)'

} else {

popup.style.transform = 'translate3d(-50%, 100%, 0)'

}

show = !show

})