我創建了一個變得粘滯的標題,並且當它發生變化時,它會從中心的固定寬度轉換爲全寬。圖標在元素擴展時抖動
出於某種原因,隨着轉換的發生,圖標以怪異的方式晃動。
更奇怪的是,他們只是在某些寬度上晃動,所以如果你看不到我在說什麼 - 嘗試改變窗口的寬度。
下面的代碼:
HTML:
<header class="header">
<div class="bg"></div>
<div id="waypoint"></div>
<nav class="nav" id="nav">
<div class="wrapper">
<div class="container">
<ul>
<li>
<a href="#">
<span class="img-wrapper">
<img src="https://www.saunderslandscaping.ca/images/icons/droplet.svg" alt="">
</span>
<span>txt</span>
</a>
</li>
// ... more items
</ul>
</div>
</div>
</nav>
</header>
CSS:
li {
float: left;
width: 20%;
border-right: 1px solid black;
}
a {
display: block;
padding: 1em;
text-align: center;
}
.img-wrapper {
display: block;
}
.header {
position: relative;
}
.nav {
position: absolute;
bottom: 0;
width: 100%;
}
.nav.sticky .wrapper {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
bottom: auto;
background: #d0d0d0;
box-shadow: 0 5px 3px rgba(0, 0, 0, 0.3);
transition: 1s all ease;
}
.wrapper {
width: 600px;
background: rgba(255, 255, 255, 0.5);
margin: 0 auto;
}
.container {
max-width: 600px;
margin: 0 auto;
}
Here's a fiddle demoing the problem (try to change the width)。
我該如何阻止搖晃?
抖動是由於奇怪的像素大小。例如,如果您的瀏覽器寬度爲5px,並且您希望以2px爲中心,則這是不可能的。它將在左邊或右邊偏離1px。這是發生在你身上的簡化版本。 – kthornbloom
@kthornbloom是的,當過渡發生時,圖標從左向右移動直到完成。你有什麼想法如何解決它? – Gofilord