是否可以仅使用 CSS 重新创建选取框?

Is it possible to recreate marquee using CSS only?

我有一个可以使用选取框解决的需求

.ticker {
  white-space: no-wrap;
}
.item {
  display: inline-block;
  cursor: pointer;
}
<marquee class="ticker" onmouseover="this.stop()" onmouseout="this.start()">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
 </marquee>

由于选取框已弃用,我们如何使其符合 html5?

我看过几个例子,但大部分都依赖固定宽度。 在我的示例中,项目是从服务器接收的,因此可能有很多。另外,我需要在悬停时停止,因为这些项目是指向其他内容的链接。

非常感谢您的帮助,

PS:在我开始探索 javascript.

之前,我想确保我们不能在 CSS 中这样做

This codepen 有一个很好的例子可以满足您的需求。

为了让它在悬停时暂停,我添加了一个悬停状态来暂停动画: https://codepen.io/anon/pen/zzpZyg

   .marquee:hover div {
      -webkit-animation-play-state: paused; /* Safari 4.0 - 8.0 */
        animation-play-state: paused;
    }

body { margin: 20px; }

.marquee {
  height: 25px;
  width: 420px;

  overflow: hidden;
  position: relative;
}

.marquee div {
  display: block;
  width: 200%;
  height: 30px;

  position: absolute;
  overflow: hidden;

  animation: marquee 5s linear infinite;
}

.marquee span {
  float: left;
  width: 50%;
}

@keyframes marquee {
  0% { left: 0; }
  100% { left: -100%; }
}

.marquee:hover div {
  -webkit-animation-play-state: paused; /* Safari 4.0 - 8.0 */
    animation-play-state: paused;
}
<div class="marquee">
  <div>
    <span>You spin me right round, baby. Like a record, baby.</span>
    <span>You spin me right round, baby. Like a record, baby.</span>
  </div>
</div>

google 上有很多关于它的信息,只需搜索:"css3 marque",就像 Neil Kennedy 提到的那样。有一个问题与您的问题非常相似,将鼠标悬停在上面后文本停止滚动。检查下面的 link:CSS3 Marquee Effect and jsfiddle: http://jsfiddle.net/MaY5A/1/

$(".toggle").on("click", function() {
  $(".marquee").toggleClass("microsoft");
});
/* Make it a marquee */

.marquee {
  width: 450px;
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  box-sizing: border-box;
  border: 1px green solid;
}

.marquee span {
  display: inline-block;
  padding-left: 100%;
  text-indent: 0;
  border: 1px red solid;
  animation: marquee 15s linear infinite;
}

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


/* Make it move */

@keyframes marquee {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(-100%, 0);
  }
}


/* Make it pretty */

.microsoft {
  padding-left: 1.5em;
  position: relative;
  font: 16px 'Segoe UI', Tahoma, Helvetica, Sans-Serif;
}


/* ::before was :before before ::before was ::before - kthx */

.microsoft:before,
.microsoft::before {
  z-index: 2;
  content: '';
  position: absolute;
  top: -1em;
  left: -1em;
  width: .5em;
  height: .5em;
  box-shadow: 1.0em 1.25em 0 #F65314, 1.6em 1.25em 0 #7CBB00, 1.0em 1.85em 0 #00A1F1, 1.6em 1.85em 0 #FFBB00;
}

.microsoft:after,
.microsoft::after {
  z-index: 1;
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 2em;
  height: 2em;
  background-image: linear-gradient(90deg, white 70%, rgba(255, 255, 255, 0));
}


/* Style the links */

.vanity {
  color: #333;
  text-align: center;
  font: .75em 'Segoe UI', Tahoma, Helvetica, Sans-Serif;
}

.vanity a,
.microsoft a {
  color: #1570A6;
  transition: color .5s;
  text-decoration: none;
}

.vanity a:hover,
.microsoft a:hover {
  color: #F65314;
}


/* Style toggle button */

.toggle {
  display: block;
  margin: 2em auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Wanted to see how easily marquees could be constructed with CSS:
     - This demo uses -prefix-free to avoid vendor prefixes
     - It also requires manual setting of the end text-indent
     - Everything below the /* Make it pretty */ comment is non-essential
     - Brought to you by @jonathansampson -->
<p class="microsoft marquee"><span>Windows 8 and Windows RT are focused on your life—your friends and family, your apps, and your stuff. With new things like the <a href="http://windows.microsoft.com/en-US/windows-8/start-screen">Start screen</a>, <a href="http://windows.microsoft.com/en-US/windows-8/charms">charms</a>, and a <a href="http://windows.microsoft.com/en-US/windows-8/microsoft-account">Microsoft account</a>, you can spend less time searching and more time doing.</span></p>
<button class="toggle">Toggle Beautification</button>
<p class="vanity">
  <a href="https://twitter.com/jonathansampson">@jonathansampson</a> of
  <a href="https://twitter.com/appendTo">@appendTo</a>
</p>

我不擅长java脚本

但这里是使用 html 和 css

PS。鼠标悬停在这里不起作用

.wrapper {
  position: relative;
  overflow: hidden;
  height: 25px;
  width: 100px;
  border: 1px solid orange;
}

.wrapper p {
  position: absolute;
  margin: 0;
  line-height: 25px;
  white-space: nowrap;
  animation: marquee 5s linear infinite;
}

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}
<div class="wrapper">
  <p>Hey, how you're doing? .</p>
</div>

我终于找到了一个好用的,这是最终的产品https://fiddle.sencha.com/#view/editor&fiddle/228u

这是原文,https://codepen.io/lewismcarey/pen/GJZVoG

<div class="wrapper">
    <div class="container">
       <span>Span Me 1</span>
       <span>Span Me 2</span>
       <span>Span Me 3</span>
       <span>Span Me 4</span>
    </div>
</div>

诀窍是 "left-pad" 包装器最初隐藏容器。然后,"right-pad" 容器,以便仅在容器离开屏幕后才 stops/restarts 动画。两个填充的大小都是相对的。 display: block; 被添加到容器中,以便正确的填充使用包装器的大小。最后,我们在包装器的转换属性上添加动画。

谢谢大家,

对不起,我知道我迟到了。但是,我有一个简单的解决方案来创建带有 CSS.

的选取框

.marquee-container{
  overflow:hidden;
}
.marquee{
  min-width:100%;
  animation: marquee 15s linear infinite;
}
.marquee:hover{
  animation-play-state: paused;
}
@keyframes marquee {
  from{margin-left : 120%;}
    to{margin-left: -20%;}
} 
<div class="marquee-container">
    <p class="marquee">
      <span>Item 1</span>
      <span>Item 2</span>
      <span>Item 3</span>
      <span>Item 4</span>
    </p>
</div>