首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >旋转木马上的圆点

旋转木马上的圆点
EN

Stack Overflow用户
提问于 2022-09-02 14:53:31
回答 2查看 229关注 0票数 0

我做了一个简单的旋转木马:

代码语言:javascript
复制
.index {
  background-color: var(--color-blue);
}

.container {
  display: flex;
  overflow: auto;
  outline: 10px solid black;
  flex: none;
}

.container.x {
  width: 100%;
  flex-flow: row nowrap;
}

.x.mandatory-scroll-snapping {
  scroll-snap-type: x mandatory;
}

.container > div {
  text-align: center;
  scroll-snap-align: center;
  flex: none;
}

.carousel-card {
  width: 100vw;
  height: 30rem;
}

h1 {
  color: blue;
  
}

h2 {
  color: red;
}

h3 {
  color: green;
}

h1, h2, h3 {
  font-size: 10rem
}
代码语言:javascript
复制
<div class="index">
        <div class="container x mandatory-scroll-snapping" dir="ltr">
          <div class="carousel-card">
                    <h1>ONE<h1>
          </div>
                  <div class="carousel-card">
                    <h2>TWO</h2>
          </div>
                  <div class="carousel-card">
                    <h3>THREE</h3>
          </div>
        </div>
    </div>

我想保持水平滚动(它是为移动),但我想添加一个div一些点和高亮活动的一个。

当然,如果没有引导、jquery或任何其他库(否则我就已经这么做了)。

我试着钻研这个,但我找不到答案:

https://developer.mozilla.org/en-US/docs/Web/CSS/:target

感谢你的帮助:)!

EN

回答 2

Stack Overflow用户

发布于 2022-09-02 15:46:50

你甚至不需要目标,你可以简单地锚定到旋转木马内的div。

代码语言:javascript
复制
.index {
  background-color: var(--color-blue);
}

.container {
  display: flex;
  overflow: auto;
  outline: 10px solid black;
  flex: none;
}

.container.x {
  width: 100%;
  flex-flow: row nowrap;
}

.x.mandatory-scroll-snapping {
  scroll-snap-type: x mandatory;
}

.container > div {
  text-align: center;
  scroll-snap-align: center;
  flex: none;
}

.carousel-card {
  width: 100vw;
  height: 30rem;
}

h1 {
  color: blue;
}

h2 {
  color: red;
}

h3 {
  color: green;
}

h1, h2, h3 {
  font-size: 10rem
}
代码语言:javascript
复制
<div class="index">
  <div class="container x mandatory-scroll-snapping" dir="ltr">
          <div id="cardOne" class="carousel-card">
                    <h1>ONE</h1>
          </div>
                  <div id="cardTwo" class="carousel-card">
                    <h2>TWO</h2>
          </div>
                  <div id="cardThree" class="carousel-card">
                    <h3>THREE</h3>
          </div>
  </div>
</div>

<ul>
<li><a href="#cardOne">One</a></li>
<li><a href="#cardTwo">Two</a></li>
<li><a href="#cardThree">Three</a></li>
</ul>

票数 0
EN

Stack Overflow用户

发布于 2022-09-02 17:28:59

我把每件事都做了进一步,添加了点(使用Font ),以及一个活动状态。我已经删除了滚动条,并将scroll-behavior设置为光滑。你的卷轴快照也很好。

如果需要更多的改变,请告诉我。

代码语言:javascript
复制
let activeDots = document.querySelectorAll('.dot');

activeDots.forEach(activeDot => {
  activeDot.addEventListener('click', e => {
    document.querySelector('.dot.active').classList.remove('active');
    e.target.classList.add('active');
  });
});
代码语言:javascript
复制
::-webkit-scrollbar {
  display: none;
}

html {
  scroll-behavior: smooth;
}

ul {
  list-style: none;
}

.dots-container {
  display: flex;
  justify-content: center;
}

ul.dots {
  display: flex;
}

.dots li+li {
  margin-left: .5rem;
}

.active {
  color: yellow;
}

.index {
  background-color: var(--color-blue);
  height: 85vh;
}

.container {
  display: flex;
  overflow: auto;
  flex: none;
}

.container.x {
  width: 100%;
  flex-flow: row nowrap;
}

.x.mandatory-scroll-snapping {
  scroll-snap-type: x mandatory;
}

.container>div {
  text-align: center;
  scroll-snap-align: center;
  flex: none;
}

.carousel-card {
  width: 100vw;
  height: 23rem;
}

h1 {
  color: blue;
}

h2 {
  color: red;
}

h3 {
  color: green;
}

h1,
h2,
h3 {
  font-size: 10rem
}

.dot::before {
  display: inline-block;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
}

.dot::before {
  font: var(--fa-font-solid);
  content: "\f111";
}
代码语言:javascript
复制
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">

<div class="index">
  <div class="container x mandatory-scroll-snapping" dir="ltr">
    <div id="cardOne" class="carousel-card">
      <h1>ONE</h1>
    </div>
    <div id="cardTwo" class="carousel-card">
      <h2>TWO</h2>
    </div>
    <div id="cardThree" class="carousel-card">
      <h3>THREE</h3>
    </div>
  </div>
  <div class="dots-container">
    <ul class="dots">
      <li>
        <a class="dot active" href="#cardOne"></a>
      </li>
      <li>
        <a class="dot" href="#cardTwo"></a>
      </li>
      <li>
        <a class="dot" href="#cardThree"></a>
      </li>
    </ul>
  </div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73584444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档