js+css实现横向滚动足球年份大事记效果代码

代码语言:html

所属分类:加载滚动

代码描述:js+css实现横向滚动足球年份大事记效果代码,底部可横向拖动,点击年份范围可进行滚动切换,点击上下运动小球可显示文字。

代码标签: js css 横向 滚动 足球 年份 大事记

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
<style>
@import url('https://fonts.googleapis.com/css2?family=Prompt:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

:root {
  --title-1: 3.2rem;
  --title-2: 1.6rem;
  --title-3: 1.25rem;
  --text: 1rem;
  --emoji: 2.5rem;
  --grey-light: #f5f5f5;
    /* colours based on UEFA's Euro 2024 identity */
  --white: #fff;
  --red: #fe0000;
  --blue: #143dda;
  --green: #24b760;
  --yellow: #ffca00;
  --black: #000;
}

@media only screen and (max-width: 1600px) {
  :root {
    --title-1: 2.5rem;
  }
}

@media only screen and (max-width: 1400px) {
  :root {
    --title-1: 2rem;
    --emoji: 2rem;
  }
}

@media only screen and (max-width: 1024px) {
  :root {
    --title-1: 1.5rem;
    --title-2: 1.2rem;
    --title-3: 1rem;
  }
}

@media only screen and (max-width: 767px) {
  :root {
    --title-1: 1.25rem;
    --title-2: .9rem;
    --title-3: .8rem;
    --text: .8rem;
    --emoji: 1.5rem;
  }
}

html {
  width: 100%;
  height: 100%;
  font-family: "Prompt", sans-serif;
  font-optical-sizing: auto;
  font-style: normal;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  position: relative;
  background: var(--blue);
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
  margin: 0;
}

h1 {
  font-weight: 600;
  font-size: var(--title-1);
  white-space: nowrap;
}

h2 {
  font-weight: 400;
  font-size: var(--title-2);
}

h3,
h4,
h5,
h6 {
  font-weight: 400;
  font-size: var(--title-3);
  line-height: 1.3;
  word-spacing: -2px;
}

p {
  font-size: var(--text);
  line-height: 1.3;
}

a {
  text-decoration: overline;
  transition: all .3s ease;
}

a:hover,
a:active,
a.active,
a:focus {
  outline: 0;
  text-decoration: underline;
}

button {
  transition: transform .3s ease;
}

button:hover,
button:focus {
  transform: scale(1.2);
}

header {
  width: 100%;
  position: fixed;
  top: 0;
  z-index: 9;
  color: #fff;
  pointer-events: none;
}

header:after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  top: 0;
  left: 0;
  background: var(--blue);
}

@media(max-width: 550px) {
  header:after {
    width: 100%;
    height: 10.1vh;
  }
}

nav svg {
  position: relative;
  fill: var(--blue);
  filter: drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));
}

@media(max-width: 550px) {
  nav svg {
    margin-top: 10vh;
  }
}

nav text {
  transform: translateY(-8px);
  pointer-events: auto;
}

nav a {
  font-size: .8rem;
  font-weight: 400;
  margin: 0 2rem;
  display: inline;
  opacity: .5;
  /* firefox fallback */
  fill: rgba(255, 255, 255, 0.5);
  text-decoration: none;
  pointer-events: auto;
}

@media(max-width: 1400px) {
  nav a {
    font-size: 1rem;
  }
}

nav a:hover,
nav a:active,
nav a.active,
nav a:focus {
  opacity: 1;
  fill: #fff;
  text-decoration: none;
}

.page-info {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
  padding-top: .8rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 10;
}

@media(min-height: 500px) {
  .page-info {
    padding-top: .8rem;
  }
}

@media(min-width: 280px) {
  .page-info h3 {
    white-space: nowrap;
  }
}

.score {
  font-size: var(--title-3);
  font-weight: 600;
  text-transform: uppercase;
  margin: .75rem 0;
  min-width: 70px;
  background: radial-gradient(circle at 0 0, transparent 16%, #eee 16%) top left, radial-gradient(circle at 100% 0, transparent 16%, #eee 16%) top right, radial-gradient(circle at 0 100%, transparent 16%, #eee 16%) bottom left, radial-gradient(circle at 100% 100%, transparent 16%, #eee 16%) bottom right;
  background-repeat: no-repeat;
  background-size: 50.5% 50.5%;
  color: var(--blue);
  display: inline-block;
  position: relative;
}

@media(max-width: 1024px) {
  .score {
    margin: .5rem 0;
    min-width: 50px;
  }
}

@media(max-width: 767px) {
  .score {
    margin: .25rem 0;
  }
}

.score:before {
  content: "";
  position: absolute;
  width: calc(100% - 18%);
  height: 100%;
  left: 9%;
  top: 0;
  background: linear-gradient(45deg, #ffffff 0%, #dedede 10%, #fff 20%, #f5f5f5 50%, #fff, #fff 80%, #e0e0e0 90%, #fff 100%);
  mix-blend-mode: luminosity;
  box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.7);
  z-index: 1;
}

#scoreVal {
  position: relative;
  z-index: 2;
}

.page-info .emoji {
  display: inline-block;
  animation: emoji .8s ease-in infinite alternate;
}

@media(min-width: 768x) {
  .page-info .emoji:first-of-type {
    margin-right: -.15rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes emoji {
    from {
      transform: rotate(0);
    }

    to {
      transform: rotate(20deg);
    }
  }
}

.page-info small {
  opacity: .3;
}

@media(max-width: 1024px) {
  .page-info small {
    display: none;
  }
}

.page-info small.warn {
  display: none;
  max-width: 450px;
  word-spacing: -2px;
}

@media(max-width: 1200px) {
  .page-info small.warn {
    max-width: 250px;
    line-height: 1;
    font-size: 12px;
  }
}

@media(max-height: 500px) and (min-width: 768px) {
  .page-info small.warn {
    display: block;
  }
}

main {
  height: 100vh;
}

#sections {
  display: flex;
  width: 100%;
  height: 100vh;
  overflow-x: scroll;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
}

.section {
  flex: 0 0 100%;
  height: 100%;
  display: flex;
  scroll-snap-align: start;
}

.item {
  position: relative;
  flex: 0 1 calc(100vw/6);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  color: #fff;
  transition: all .3s ease;
}

.item.active {
  flex: 0 1 calc(100vw/3);
}

.item-info {
  position: relative;
  padding: 0 1rem .2rem;
  text-align: center;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  width: 100%;
  max-width: 400px;
}

@media only screen and (max-width: 767px) {
  .item-info {
    padding: 0 .25rem .7rem;
  }
}

.item-trigger {
  appearance: none;
  background: none;
  border: 0;
  height: var(--emoji);
  font-size: var(--emoji);
  padding: 0 6px;
  margin: 6px 0;
  text-align: center;
  border-radius: 50%;
  cursor: pointer;
  translate: 0 0;
  text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.7);
  animation: ball .6s cubic-bezier(0, 0, 0.2, 1) infinite alternate;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes ball {
    from {
      translate: 0 0;
    }

    to {
      translate: 0 -50px;
    }
  }
}

.item-info h2 {
  position: relative;
  width: fit-content;
}

.item-info p {
  min-height: 40px;
  opacity: 0;
  width: 0;
  text-indent: -9999px;
  overflow: hidden;
  transition: all 0s linear;
}

.item.active .item-info p {
  text-indent: 0;
  width: 100%;
  opacity: 1;
  transition: text-indent .3s, opacity .15s ease .3s;
}

@media only screen and (max-height: 500px) {
  .item-info p {
    font-size: smaller;
  }
}

.white {
  background: var(--white);
  color: #000;
}

.red {
  background: var(--red);
}

.blue {
  background: var(--blue);
}

.green {
  background: var(--green);
}

.yellow {
  background: var(--yellow);
  color: #000;
}

.black {
  background: var(--black);
}

.item[data-scored="true"] .item-info h2:after {
  content: "";
  position: absolute;
  right: -.8rem;
  top: calc(var(--title-2) / 2);
  display: inline-block;
  transform: rotate(45deg);
  height: 10px;
  width: 5px;
  border-bottom: 1.5px solid #fff;
  border-right: 1.5px solid #fff;
}

.yellow.item[data-scored="true"] .item-info h2:after,
.white.item[data-scored="true"] .item-info h2:after {
  border-color: #000;
}

@media only screen and (max-width: 767px) {
  .item[data-scored="true"] .item-info h2:after {
    content: "";
    position: absolute;
    right: calc(var(--title-2));
    top: calc(var(--title-2) + .2rem);
    display: inline-block;
    transform: rotate(45deg);
  }
}
</style>


  
</head>

<body translate="no">

  <header>
    <div class="page-info">
      <small>#cpc-horizontal-scrolling</small>
      <h1>UEFA EURO challenge</h1>
      <h3><span class="emoji">👆</span> scroll left/right + intercept the balls <span class="emoji">⚽</span></h3>
      <div class="score" aria-label="score"><span id="scoreVal">0/18</span></div>
      <small class="warn">[please adjust screen height]
      </small>
    </div>
    <nav>
      <svg version="1.1" id="svg-nav" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
        x="0px" y="0px" viewBox="0 0 500 118" xml:space="preserve">
        <path id="curve" d="M0,0c59.914,71.192,149.668,116.439,250,116.439c100.332,0,190.086-45.246,250-116.439" />
        <text>
          <textPath xlink:href="#curve" startOffset="18%">
            <a class="nav-link" href="#1960-1980">1960–1980</a>
          </textPath>
        </text>
        <text>
          <textPath xlink:href="#curve" startOffset="43%">
            <a class="nav-link" href="#1984-2004">1984–2004</a>
          </textPath>
        </text>
        <text>
          <textPath xlink:href="#curve" startOffset="68%">
            <a class="nav-link" href="#2008-2028">2008–2028</a>
          </textPath>
        </text>
      </svg>
    </nav>
  </header>
  <main>
    <div id="sections" tabindex="0">
      <div id="1960-1980" class="section">
        <div id="1960" class="item white" data-scored="false">
          <button type="button" class="item-trigger">⚽</button>
          <div class="item-info">
            <h2>1960</h2>
            <p>The first-ever edition of the UEFA European Championship.</p>
          </div>
        </div>
        <div id="1964" class="item red" data-scored="false">
          <button type="button" class="item-trigger">⚽</button>
          <div class="item-info".........完整代码请登录后点击上方下载按钮下载查看

网友评论0