侧边栏增加8+自动轮播广告位,文字版+图片版


------正文内容展示,开始汲取新知识啦------

文字版轮播+图片轮播两种样式代码,时间可以自己调整,没有做测试,希望用了的兄弟评论里发个演示哈。

文字版

<style>
  .advertise-container {
    width: 100%;
    height: 100px;
    overflow: hidden;
    position: relative;
    text-align: center;
  }
  .advertise-container .advertise-item {
    width: 100%;
    height: 100px;
    position: absolute;
    top: 0;
    left: 0;
  }
  .advertise-container a {
    display: inline-block;
    width: 100%;
    height: 100%;
    line-height: 100px;
    color: #000;
    font-weight: bold;
    text-decoration: none;
    font-size: 24px;
    animation: pulse 2s ease infinite;
    background: transparent;
  }
  @keyframes pulse {
    0% {
      color: #000;
    }
    50% {
      color: #f00;
    }
    100% {
      color: #000;
    }
  }
</style>

<div class="advertise-container">
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位1</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位2</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位3</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位4</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位5</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位6</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位7</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位8</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位9</div>
  </a>
  <a href="https://www.uzhix.com/" target="_blank">
    <div class="advertise-item">广告位10</div>
  </a>
</div>

<script>
  var advertise = document.querySelectorAll('.advertise-item');
  var index = 0;
  setInterval(function() {
    advertise.forEach(function(item) {
      item.style.display = 'none';
    })
    if (index >= advertise.length) {
      index = 0;
    }
    advertise[index].style.display = 'block';
    index++;
  }, 2000)
</script>

 

图片版

<style>
  .advertise-container {
    width: 100%;
    height: 100px;
    overflow: hidden;
    position: relative;
  }
  .advertise-container .advertise-item {
    width: 100%;
    height: 100px;
    position: absolute;
    top: 0;
    left: 0;
    object-fit: cover;
  }
  .advertise-container a {
    display: inline-block;
    width: 100%;
    height: 100%;
    line-height: 100px;
    color: #000;
    font-weight: bold;
    text-decoration: none;
    font-size: 24px;
    animation: pulse 2s ease infinite;
    background: transparent;
    text-align: center;
  }
  .advertise-container img {
    width: 100%;
    height: 100%;
  }
  @keyframes pulse {
    0% {
      color: #000;
    }
    50% {
      color: #f00;
    }
    100% {
      color: #000;
    }
  }
</style>

<div class="advertise-container">
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位1"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="图片链接" alt="广告位2"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="图片链接" alt="广告位3"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="图片链接" alt="广告位4"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位5"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位6"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位7"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位8"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位9"></div>
  </a>
  <a href="https://www.baidu.com" target="_blank">
    <div class="advertise-item"><img src="https://www.baidu.com/img/baidu_jgylogo3.gif" alt="广告位10"></div>
  </a>
</div>

<script>
  var advertise = document.querySelectorAll('.advertise-item');
  var index = 0;
  setInterval(function() {
    advertise.forEach(function(item) {
      item.style.display = 'none';
    })
    if (index >= advertise.length) {
      index = 0;
    }
    advertise[index].style.display = 'block';
    index++;
  }, 2000)
</script>

 

 

温馨提示:本文最后更新于2023-07-29 17:28:00,某些文章具有时效性,若有错误或已失效,请私信客服或联系知新社长
------本文内容已结束,喜欢请分享------

感谢您的访问,Ctrl+D收藏本站吧。

© 版权声明
三月 3

知岛上的今时往日

THE END
点赞0投币 分享
评论 抢沙发
头像
善语结善缘,恶言伤人心。(禁止发送无意义的字符)
提交
头像

昵称

夸夸Ta
夸夸
还有吗!没看够!
取消
昵称表情代码图片

    暂无评论内容

社区求救信号帮助是一种美德