我知道我在談論IE,但我認爲transition
屬性已修復更新(Edge?)版本。IE /邊緣CSS3過渡不與後臺位置屬性
我想過渡元素的background-position
(見下面的演示),但不管是什麼原因,它不是在IE工作...:' - (
在下面的演示中,‘點擊我’按鈕應突出相鄰的文本,但不是那麼的IE瀏覽器。
如果選中「切換顯示」按鈕,你會看到背景顏色顯示出來(當然,轉型後),因爲切換display:none
是迫使重繪。我知道background-size
可能不是transition
- 在IE中,但是這會影響background-position
上的單個轉換屬性嗎? lor從左到右過渡(請參閱除IE以外的其他瀏覽器中的演示以獲得所需的效果)?
謝謝!
/** JS only to facilitate the test and trigger the CSS on button click **/
var myHighlighter = document.querySelector('.button');
var myToggle = document.querySelector('.toggle');
myHighlighter.addEventListener('click', press)
// toggling `display:none` just forces a repaint
myToggle.addEventListener('click', toggle);
function press(e) {
var newState = (e.target.getAttribute('aria-pressed')!=="true");
e.target.setAttribute('aria-pressed', newState);
}
function toggle(e) {
var isToggled = (e.target.previousElementSibling.getAttribute('style'))
if (isToggled) {
e.target.previousElementSibling.removeAttribute('style');
} else {
e.target.previousElementSibling.setAttribute('style', 'display:none;');
}
}
/* conditional CSS for transition based on presence of `aria-pressed="true"` attribute */
.button + .text {
background: linear-gradient(to right, orange 50%, transparent 50%) no-repeat;
background-position:right bottom;
background-size: 200% 100%;
transition: none;
}
.button[aria-pressed="true"] + .text {
background-position: left bottom;
transition: background-position .5s linear;
}
<div class="wrapper">
<button type="button"
class="button"
aria-pressed="false">
Click Me
</button>
<span class="text">IE won't transition the background-position (color highlighting) initially without toggleing the display (repaint)</span>
<button class="toggle">Toggle Display</button>
</div>
哪個版本的IE?在IE 10中,轉換不起作用。 – Rob