2016-12-09 173 views
0

我发现this awesome CSS-Marquee,它几乎适用于所有浏览器,但不幸的是不在MS Edge上。当你将鼠标悬停在字幕是应该停止,但边缘不喜欢MS边缘上的CSS Marquee

.marquee span:hover 
{ 
    animation-play-state: paused; 
} 

它甚至更糟,因为边缘使其无法标志着字幕文本和跑马灯各个环节都坏了。

下面是完整的代码:

<div class="marquee"> 
    <span>Some long text with a few <a href="#">Links</a> and bla bla</span> 
</div> 

/* define the animation */ 
@keyframes marquee 
{ 
    0% { transform: translate(0, 0); } 
    100% { transform: translate(-100%, 0); } 
} 

/* define your limiting container */ 
.marquee 
{ 
    width: 100%; 
    margin: 0 auto; 
    white-space: nowrap; 
    overflow: hidden; 
    box-sizing: border-box; 
} 

/* this is the tray moving around your container */ 
.marquee span 
{ 
    display: inline-block; 
    padding-left: 100%; 
    text-indent: 0; 
    animation: marquee 60s linear infinite; /* here you select the animation */ 
} 

/* pause the animation on mouse over */ 
.marquee span:hover 
{ 
    animation-play-state: paused; 
} 

对于任何解决方案?也许一个单独的边缘CSS? 对于不同的文本长度,可以使动画速度相同吗?编辑: 行!所以,我发现了一个方法,使速度与不同的文本lenght相同:

<script> 
function calcSpeed(speed) { 
// Time = Distance/Speed 
var spanSelector = document.querySelector('.marquee span'); 
var spanLength = spanSelector.offsetWidth; 
var timeTaken = spanLength/speed; 
spanSelector.style.animationDuration = timeTaken + "s"; 
} 
calcSpeed(100); 
</script> 

但仍有问题,该边缘不喜欢“动画播放状态:暂停;”并打破Marquee中的所有链接

+0

我不知道CSS是否可能只针对Edge,但您可以尝试像将动画部分放在'.marquee span:not(:hover)'中,这样您就可以避免使用动画播放功能, state'。 –

+1

此功能已过时。虽然它可能在某些浏览器中仍然有效,但它的使用是不鼓励的,因为它可以在任何时候被删除。尽量避免使用它。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/marquee –

+0

我不使用旧的默认!这是一个CSS动画! – Exo

回答

0

好的!这是我的解决方案! 它现在有不同的文本长度相同的速度,如果使用Edge,我会覆盖css。现在,如果您将鼠标悬停在“选取框”上并处于“边缘”动画播放状态,几乎每个浏览器都会停止选取框:已暂停;更改为动画播放状态:正在运行;

下面是相同的速度码:

<script> 
function calcSpeed(speed) { 
// Time = Distance/Speed 
var spanSelector = document.querySelector('.marquee span'); 
var spanLength = spanSelector.offsetWidth; 
var timeTaken = spanLength/speed; 
spanSelector.style.animationDuration = timeTaken + "s"; 
} 
calcSpeed(100); 
</script> 

这里是边缘代码:

@supports (-ms-ime-align:auto) { 
    .marquee span:hover { animation-play-state: running; } 
} 

如果您有在动画与边缘停止其中一个更好的解决方案,比请发布!