图片轮播大全

news2025/1/16 11:14:03

案例1:上下轮播切割重组

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      html,
      body {
        padding: 0;
        margin: 0;
        overflow: hidden;
        font-family: "Sen";
      }
      * {
        box-sizing: border-box;
        outline: none;
        -webkit-tap-highlight-color: transparent;
        cursor: none;
        user-select: none;
        -webkit-user-drag: none;
      }
      #main {
        display: flex;
      }
      #main .part {
        flex: 1;
      }
      #main .part .section {
        width: 100%;
        height: 100vh;
        position: relative;
        overflow: hidden;
      }
      #main .part .section img {
        width: 100vw;
        height: 100vh;
        object-fit: cover;
        position: absolute;
        left: var(--x);
        pointer-events: none;
      }
      .cursor {
        width: var(--size);
        height: var(--size);
        border-radius: 50%;
        background: white;
        position: absolute;
        z-index: 999;
        pointer-events: none;
        mix-blend-mode: difference;
      }
      .cursor-f {
        width: var(--size);
        height: var(--size);
        position: absolute;
        top: 0;
        left: 0;
        background-image: url("data:image/svg+xml,%3Csvg width='47' height='47' viewBox='0 0 47 47' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M42.4202 42.4202C38.8403 46 33.3594 46 23.5 46C13.6406 46 8.15966 46 4.57983 42.4202C1 38.8403 1 33.3594 1 23.5C1 13.6406 1 8.15966 4.57983 4.57983C8.15966 1 13.6406 1 23.5 1C33.3594 1 38.8403 1 42.4202 4.57983C46 8.15966 46 13.6406 46 23.5C46 33.3594 46 38.8403 42.4202 42.4202Z' stroke='white'/%3E%3C/svg%3E%0A");
        background-size: cover;
        mix-blend-mode: difference;
        pointer-events: none;
        opacity: 0.5;
      }
      .buttons {
        position: absolute;
        right: 25px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 99;
      }
      .buttons button {
        border: none;
        background-size: contain;
        background: url("data:image/svg+xml,%3Csvg width='10' height='29' viewBox='0 0 10 29' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M9 0V27L1 17.4857' stroke='white' stroke-width='2' /%3E%3C/svg%3E%0A")
          no-repeat;
        background-position: center;
        width: 10px;
        height: 30px;
        display: block;
        margin: 20px 0;
        padding: 0 15px;
        transition-duration: 0.6s;
      }
      .buttons button.next {
        transform: scaleY(-1);
      }
      .buttons button.prev:active {
        transform: translateY(8px);
      }
      .buttons button.next:active {
        transform: scaleY(-1) translateY(8px);
      }
      h1 {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        left: 0;
        right: 0;
        margin: auto;
        z-index: 99;
        color: white;
        text-align: center;
        font-size: 2.6em;
        mix-blend-mode: overlay;
        pointer-events: none;
      }
      .content {
        width: 90%;
        position: absolute;
        bottom: 20px;
        text-align: center;
        left: 0;
        right: 0;
        margin: auto;
        color: white;
        z-index: 99;
        font-size: 0.8em;
      }
      .content p {
        margin: 0.5em auto;
      }
      .content kbd {
        width: 15px;
        height: 15px;
        border: 1px solid white;
        display: inline-block;
        border-radius: 3px;
        font-size: 0.9em;
        vertical-align: text-top;
      }
      .content a {
        color: rgba(227, 227, 227, 0.78);
        text-decoration: none;
        border-bottom: 1px solid currentColor;
      }
      .content a:hover {
        padding-bottom: 1px;
      }
    </style>
  </head>
  <body>
    <div id="main">
      <h1>something</h1>
      <div class="content">
        <p>
          You can press <kbd>▲</kbd> <kbd>▼</kbd> on your keyboard or swipe
          up/down to navigate. Mouse wheel works too.
        </p>
      </div>
      <div class="buttons">
        <button class="next" onclick="go(-1)"></button>
        <button class="prev" onclick="go(1)"></button>
      </div>
    </div>
    <script src="gsap.min.js"></script>

    <script>
      const cols = 3;
      const main = document.getElementById("main");
      let parts = [];

      let images = [
        "https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2550&q=80",
        "https://images.unsplash.com/photo-1544198365-f5d60b6d8190?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2550&q=80",
        "https://images.unsplash.com/photo-1493246507139-91e8fad9978e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2700&q=80",
      ];
      let current = 0;
      let playing = false;

      for (let i in images) {
        new Image().src = images[i];
      }

      for (let col = 0; col < cols; col++) {
        let part = document.createElement("div");
        part.className = "part";
        let el = document.createElement("div");
        el.className = "section";
        let img = document.createElement("img");
        img.src = images[current];
        el.appendChild(img);
        part.style.setProperty("--x", (-100 / cols) * col + "vw");
        part.appendChild(el);
        main.appendChild(part);
        parts.push(part);
      }

      let animOptions = {
        duration: 2.3,
        ease: Power4.easeInOut,
      };

      function go(dir) {
        if (!playing) {
          playing = true;
          if (current + dir < 0) current = images.length - 1;
          else if (current + dir >= images.length) current = 0;
          else current += dir;

          function up(part, next) {
            part.appendChild(next);
            gsap
              .to(part, { ...animOptions, y: -window.innerHeight })
              .then(function () {
                part.children[0].remove();
                gsap.to(part, { duration: 0, y: 0 });
              });
          }

          function down(part, next) {
            part.prepend(next);
            gsap.to(part, { duration: 0, y: -window.innerHeight });
            gsap.to(part, { ...animOptions, y: 0 }).then(function () {
              part.children[1].remove();
              playing = false;
            });
          }

          for (let p in parts) {
            let part = parts[p];
            let next = document.createElement("div");
            next.className = "section";
            let img = document.createElement("img");
            img.src = images[current];
            next.appendChild(img);

            if ((p - Math.max(0, dir)) % 2) {
              down(part, next);
            } else {
              up(part, next);
            }
          }
        }
      }

      window.addEventListener("keydown", function (e) {
        if (["ArrowDown", "ArrowRight"].includes(e.key)) {
          go(1);
        } else if (["ArrowUp", "ArrowLeft"].includes(e.key)) {
          go(-1);
        }
      });

      function lerp(start, end, amount) {
        return (1 - amount) * start + amount * end;
      }

      const cursor = document.createElement("div");
      cursor.className = "cursor";

      const cursorF = document.createElement("div");
      cursorF.className = "cursor-f";
      let cursorX = 0;
      let cursorY = 0;
      let pageX = 0;
      let pageY = 0;
      let size = 8;
      let sizeF = 36;
      let followSpeed = 0.16;

      document.body.appendChild(cursor);
      document.body.appendChild(cursorF);

      if ("ontouchstart" in window) {
        cursor.style.display = "none";
        cursorF.style.display = "none";
      }

      cursor.style.setProperty("--size", size + "px");
      cursorF.style.setProperty("--size", sizeF + "px");

      window.addEventListener("mousemove", function (e) {
        pageX = e.clientX;
        pageY = e.clientY;
        cursor.style.left = e.clientX - size / 2 + "px";
        cursor.style.top = e.clientY - size / 2 + "px";
      });

      function loop() {
        cursorX = lerp(cursorX, pageX, followSpeed);
        cursorY = lerp(cursorY, pageY, followSpeed);
        cursorF.style.top = cursorY - sizeF / 2 + "px";
        cursorF.style.left = cursorX - sizeF / 2 + "px";
        requestAnimationFrame(loop);
      }

      loop();

      let startY;
      let endY;
      let clicked = false;

      function mousedown(e) {
        gsap.to(cursor, { scale: 4.5 });
        gsap.to(cursorF, { scale: 0.4 });

        clicked = true;
        startY =
          e.clientY || e.touches[0].clientY || e.targetTouches[0].clientY;
      }
      function mouseup(e) {
        gsap.to(cursor, { scale: 1 });
        gsap.to(cursorF, { scale: 1 });

        endY = e.clientY || endY;
        if (clicked && startY && Math.abs(startY - endY) >= 40) {
          go(!Math.min(0, startY - endY) ? 1 : -1);
          clicked = false;
          startY = null;
          endY = null;
        }
      }
      window.addEventListener("mousedown", mousedown, false);
      window.addEventListener("touchstart", mousedown, false);
      window.addEventListener(
        "touchmove",
        function (e) {
          if (clicked) {
            endY = e.touches[0].clientY || e.targetTouches[0].clientY;
          }
        },
        false
      );
      window.addEventListener("touchend", mouseup, false);
      window.addEventListener("mouseup", mouseup, false);

      let scrollTimeout;
      function wheel(e) {
        clearTimeout(scrollTimeout);
        setTimeout(function () {
          if (e.deltaY < -40) {
            go(-1);
          } else if (e.deltaY >= 40) {
            go(1);
          }
        });
      }
      window.addEventListener("mousewheel", wheel, false);
      window.addEventListener("wheel", wheel, false);
    </script>
  </body>
</html>

案例2:左右轮播(传统方式,最常见的一种)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Image Slider</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        font-family: Arial, sans-serif;
        background-color: #f4f4f4;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        overflow: hidden;
      }

      #slider-container {
        position: relative;
        width: 600px;
        height: 400px;
        overflow: hidden;
      }

      #image-slider {
        display: flex;
        transition: transform 0.5s ease-in-out;
        height: 100%;
      }

      .slide {
        min-width: 100%;
        box-sizing: border-box;
      }

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      #prev,
      #next {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        font-size: 24px;
        cursor: pointer;
        color: #333;
        background-color: #fff;
        padding: 10px;
        border: 1px solid #ccc;
        border-radius: 5px;
      }

      #prev {
        left: 10px;
      }

      #next {
        right: 10px;
      }

      .indicator-container {
        position: absolute;
        bottom: 15px;
        padding: 5px 5px;
        left: 50%;
        transform: translateX(-50%); /* 使用负的50%的平移来实现水平居中 */
        width: auto;
        height: auto;
        border-radius: 7px;
        background: rgba(158, 154, 154, 0.7);
        display: flex;
        justify-content: space-between;
      }

      .indicator {
        width: 8px;
        height: 8px;
        margin: 0 10px;
        border-radius: 50%;
        background-color: #fff;
        cursor: pointer;
      }

      .indicator.selected {
        background-color: rgb(255, 153, 0);
      }
    </style>
  </head>
  <body>
    <div id="slider-container">
      <div id="image-slider">
        <div class="slide">
          <img
            src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g7/M00/08/0A/ChMkLGPgV8yIByPqAEBpHxFxY58AAMhuQO39iYAQGk3263.jpg"
            alt="Slide 1"
          />
        </div>
        <div class="slide">
          <img
            src="https://b.zol-img.com.cn/desk/bizhi/image/11/960x600/1675646737470.jpg"
            alt="Slide 2"
          />
        </div>
        <div class="slide">
          <img
            src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g7/M00/08/0A/ChMkLGPgV-iID9g0AEjGoSWnrl4AAMhvAH0En8ASMa5359.jpg"
            alt="Slide 3"
          />
        </div>
        <!-- Add more slides as needed -->
        <div class="slide">
          <img
            src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g7/M00/08/0A/ChMkLGPgV8yIByPqAEBpHxFxY58AAMhuQO39iYAQGk3263.jpg"
            alt="Slide 1"
          />
        </div>
      </div>
      <div id="prev" onclick="changeSlide(-1)">❮</div>
      <div id="next" onclick="changeSlide(1)">❯</div>
      <div class="indicator-container">
        <div class="indicator selected" onclick="changeSlideTo(0)"></div>
        <div class="indicator" onclick="changeSlideTo(1)"></div>
        <div class="indicator" onclick="changeSlideTo(2)"></div>
        <!-- Add more indicators as needed -->
      </div>
    </div>

    <script>
      let currentSlide = 0; // 当前幻灯片索引
      const totalSlides = document.querySelectorAll(".slide").length - 1; // 幻灯片总数(减去克隆的一张)
      const slider = document.getElementById("image-slider"); // 幻灯片容器元素
      const indicators = document.querySelectorAll(".indicator");
      const slidercontainer = document.getElementById("slider-container");
      // 切换幻灯片
      function changeSlide(direction) {
        currentSlide += direction; // 更新当前幻灯片索引

        if (currentSlide > totalSlides) {
          // 如果当前索引超过最大索引,执行无缝循环
          slider.style.transition = "none"; // 去掉过渡效果
          currentSlide = 0; // 回到第一张幻灯片
          slider.style.transform = "translateX(0)"; // 瞬间移动到第一张的位置
          setTimeout(() => {
            slider.style.transition = "transform 0.5s ease-in-out"; // 恢复过渡效果
            currentSlide += direction; // 更新索引
            translateSlider(); // 移动到下一张幻灯片
          }, 0);
        } else if (currentSlide < 0) {
          // 如果当前索引小于0,执行无缝循环
          slider.style.transition = "none"; // 去掉过渡效果
          currentSlide = totalSlides; // 移动到最后一张幻灯片
          slider.style.transform = "translateX(" + -totalSlides * 100 + "%)"; // 瞬间移动到最后一张的位置
          setTimeout(() => {
            slider.style.transition = "transform 0.5s ease-in-out"; // 恢复过渡效果
            currentSlide += direction; // 更新索引
            translateSlider(); // 移动到下一张幻灯片
          }, 0);
        } else {
          translateSlider(); // 正常移动到下一张幻灯片
        }
      }

      // 移动到指定位置
      function translateSlider() {
        const translateValue = -currentSlide * 100 + "%"; // 计算移动距离
        slider.style.transform = "translateX(" + translateValue + ")"; // 设置移动
        updateIndicators(); // 更新指示器
      }

      // 移动到指定索引的幻灯片
      function changeSlideTo(index) {
        currentSlide = index;
        translateSlider();
      }

      // 更新指示器状态
      function updateIndicators() {
        console.log("------updateIndicators------");
        indicators.forEach((indicator, index) => {
          console.log(index, currentSlide);
          if (index === currentSlide) {
            console.log("激活", currentSlide, totalSlides);
          }

          indicator.classList.toggle("selected", index === currentSlide);
        });
        //   特殊情况处理,解决:备用image的指示器无法正常更新的问题
        // 如果当前是最后一张
        if (totalSlides === currentSlide) {
          console.log(
            "特殊情况处理,解决:备用image的指示器无法正常更新的问题",
            totalSlides,
            currentSlide
          );
          indicators[0].classList.toggle("selected");
        }
      }

      // 定义自动切换的时间间隔(单位:毫秒)
      const autoSlideInterval = 2000;

      // 设置自动切换定时器
      var autoSlideTimer = setInterval(() => {
        changeSlide(1); // 切换到下一张图片
      }, autoSlideInterval);

      // 停止自动切换的定时器,当鼠标进入幻灯片区域时停止自动切换
      slidercontainer.addEventListener("mouseenter", () => {
        console.log("mouseenter-清除定时器");
        clearInterval(autoSlideTimer);
      });

      // 恢复自动切换的定时器,当鼠标离开幻灯片区域时恢复自动切换
      slidercontainer.addEventListener("mouseleave", () => {
        console.log("mouseleave-增加定时器");
        autoSlideTimer = setInterval(() => {
          changeSlide(1); // 切换到下一张图片
        }, autoSlideInterval);
      });
    </script>
  </body>
</html>

案例3:匀速播放(看实际需求)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
  </head>
  <style>
    body,
    div,
    ul,
    li,
    p {
      padding: 0;
      margin: 0;
    }

    #div1 {
      position: relative;
      margin: 10px auto;
      border: 1px solid black;
      width: 680px;
      height: 170px;
      overflow: hidden;
    }

    #div1 ul {
      position: absolute;
      left: 0;
    }

    #div1 ul li {
      float: left;
      padding: 10px;
      list-style: none;
      width: 150px;
      height: 150px;
    }

    #div1 ul li img {
      width: 150px;
      height: 150px;
    }
    h1 {
      text-align: center;
    }
  </style>
  <body>
    <h1>通过控制iSpeed变量控制方向</h1>

    <div id="div1">
      <ul>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F12f18496-3075-4367-b599-ae390f0e0b37%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=ac9c35bc3241e3c7064bbd6ff0825f26"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F47c3b9ca-945f-4722-be80-ee68f856fc5d%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=0b5c2721036e75f2003b57d10d525959"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F4d40b566-1f0a-4f8d-bc97-c513df8775b3%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=6061840a2056a61ed620e00200725336"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fc5f6153c-589f-4b46-a371-705652eeb8ec%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=7cda4ac6e5655353e36d4754983b95a1"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F600e0252-5aec-4d5f-826b-795848bba7e0%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=6a46723df4e4c0b70763ca11fb9392bb"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F3ea167ef-8f98-401d-b1e1-173e4d2e06cf%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=b9ffce8d28c7e78304d93597d6211bf9"
            alt=""
          />
        </li>
      </ul>
    </div>
    <script type="text/javascript">
      window.onload = function () {
        var oDiv = document.getElementById("div1");
        var oUl = document.getElementsByTagName("ul")[0];
        var oLi = document.getElementsByTagName("li");
        var oA = document.getElementsByTagName("a");
        var timer = null;
        var iSpeed = -1;
        //复制一遍ul
        oUl.innerHTML += oUl.innerHTML;
        //ul的宽度是所有li宽度之和,复制ul之后的整个ul的宽度就是li的长度乘以一个li的宽度
        oUl.style.width = oLi.length * oLi[0].offsetWidth + "px";

        function fnMove() {
          //图片向左移动时的条件,即在div里的ul的offsetLeft小于一个ul的宽度
          if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
            //将整个复制的ul向右拖拽直至整个ul中的第一张图归位到起点
            oUl.style.left = 0;
          }
          //图片向右移动时的条件,即在div里的ul的offsetLeft大于等于0
          else if (oUl.offsetLeft >= 0) {
            //将整个复制的ul向左拖拽直至整个ul中的第一张图归位到起点
            oUl.style.left = -oUl.offsetWidth / 2 + "px";
          }
          //给ul一个速度让整个ul的offsetLeft增加或减少,速度为正则向右移动,速度为负则向左移动
          oUl.style.left = oUl.offsetLeft + iSpeed + "px";
        }
        //从左往右
        // iSpeed = -1;
        //自动滚动
        timer = setInterval(fnMove, 10);
        //当鼠标移动到div里面的时候图片滚动暂停,此时清除定时器即可。
        oDiv.onmouseover = function () {
          clearInterval(timer);
        };
        //当鼠标移出div的时候图片继续滚动,此时重新加载定时器。
        oDiv.onmouseout = function () {
          timer = setInterval(fnMove, 10);
        };
      };
    </script>
  </body>
</html>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>无缝滚动_从上往下</title>
  </head>
  <style>
    body,
    div,
    ul,
    li,
    p {
      padding: 0;
      margin: 0;
    }

    #div1 {
      position: relative;
      margin: 50px auto;
      border: 1px solid black;
      width: 170px;
      height: 680px;
      overflow: hidden;
    }

    #div1 ul {
      position: absolute;
      left: 0;
    }

    #div1 ul li {
      float: left;
      padding: 10px;
      list-style: none;
      width: 150px;
      height: 150px;
    }

    #div1 ul li img {
      width: 150px;
      height: 150px;
    }
    h1 {
      text-align: center;
    }
  </style>
  <body>
    <h1>通过控制iSpeed变量控制方向</h1>
    <div id="div1">
      <ul>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F12f18496-3075-4367-b599-ae390f0e0b37%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=ac9c35bc3241e3c7064bbd6ff0825f26"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F47c3b9ca-945f-4722-be80-ee68f856fc5d%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=0b5c2721036e75f2003b57d10d525959"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F4d40b566-1f0a-4f8d-bc97-c513df8775b3%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=6061840a2056a61ed620e00200725336"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fc5f6153c-589f-4b46-a371-705652eeb8ec%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=7cda4ac6e5655353e36d4754983b95a1"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F600e0252-5aec-4d5f-826b-795848bba7e0%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=6a46723df4e4c0b70763ca11fb9392bb"
            alt=""
          />
        </li>
        <li>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F3ea167ef-8f98-401d-b1e1-173e4d2e06cf%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1708427206&t=b9ffce8d28c7e78304d93597d6211bf9"
            alt=""
          />
        </li>
      </ul>
    </div>
    <script type="text/javascript">
      window.onload = function () {
        var oDiv = document.getElementById("div1");
        var oUl = document.getElementsByTagName("ul")[0];
        var oLi = document.getElementsByTagName("li");
        var oA = document.getElementsByTagName("a");
        var timer = null;
        var iSpeed = -1;
        //复制一遍ul
        oUl.innerHTML += oUl.innerHTML;
        //ul的高度是所有li高度之和,复制ul之后的整个ul的高度就是li的长度乘以一个li的高度
        oUl.style.height = oLi.length * oLi[0].offsetHeight + "px";

        function fnMove() {
          //图片向上移动时的条件,即在div里的ul的offsetTop小于一个ul的高度
          if (oUl.offsetTop < -oUl.offsetHeight / 2) {
            //将整个复制的ul向下拖拽直至整个ul中的第一张图归位到起点
            oUl.style.top = 0;
          }
          //图片向下移动时的条件,即在div里的ul的offsetTop大于等于0
          else if (oUl.offsetTop >= 0) {
            //将整个复制的ul向上拖拽直至整个ul中的第一张图归位到起点
            oUl.style.top = -oUl.offsetHeight / 2 + "px";
          }
          //给ul一个速度让整个ul的offsetTop增加或减少,速度为正则向下移动,速度为负则向上移动
          oUl.style.top = oUl.offsetTop + iSpeed + "px";
        }
        //自动滚动
        timer = setInterval(fnMove, 10);
        //当鼠标移动到div里面的时候图片滚动暂停,此时清除定时器即可。
        oDiv.onmouseover = function () {
          clearInterval(timer);
        };
        //当鼠标移出div的时候图片继续滚动,此时重新加载定时器。
        oDiv.onmouseout = function () {
          timer = setInterval(fnMove, 10);
        };
      };
    </script>
  </body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1400938.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[陇剑杯 2021]webshell

[陇剑杯 2021]webshell 题目做法及思路解析&#xff08;个人分享&#xff09; 问一&#xff1a;单位网站被黑客挂马&#xff0c;请您从流量中分析出webshell&#xff0c;进行回答&#xff1a; 黑客登录系统使用的密码是_____________。 题目思路&#xff1a; 分析题目&…

幻兽帕鲁开服教程——游戏

幻兽帕鲁开服教程——游戏 1. 安装服务器2. 服务器配置调整3. 运行环境Microsoft Visual C Runtime4. 加入服务器 这是研究开服时顺手写的笔记&#xff0c;也方便后来者。 如果你熟悉你所使用的操作系统的话&#xff0c;windows和linux应该区别不大。 1. 安装服务器 1.安装ste…

什么是小程序?特点和技术架构详解

小程序是一种新的移动应用程序格式&#xff0c;一种结合了 Web 技术以及客户端技术的混合解决方案。 传统的原生应用运行起来比较流畅&#xff0c;但是也有天然的基因缺陷&#xff1a; 不支持动态化&#xff0c;发布周期长需要开发Android和iOS两套代码&#xff0c;开发成本高…

Ubuntu系统安装(如何在虚拟机下安装Ubuntu系统)

前言 Linux 的开发需要在 Linux 系统下进行&#xff0c;这就要求我们的 PC 主机安装 Linux 系统。我会在这篇文章中分享我如何安装虚拟机&#xff0c;以及我在虚拟机下安装Ubuntu系统。相信我的分享一定会给你带来帮助。 目录 前言 一、安装虚拟机软件 二、创建虚拟机 三、…

Kafka(八)使用Kafka构建数据管道

目录 1 使用场景2 构建数据管道时需要考虑的问题2.1 及时性2.2 可靠性高可用可靠性数据传递 2.3 高吞吐量2.4 数据格式2.5 转换ETLELT 2.6 安全性2.7 故障处理2.8 耦合性和灵活性临时数据管道元数据丢失末端处理 3 使用Connect API3.1 Connect的数据处理流程sourcesinkconnecto…

【C++】List模拟实现过程中值得注意的点

&#x1f440;樊梓慕&#xff1a;个人主页 &#x1f3a5;个人专栏&#xff1a;《C语言》《数据结构》《蓝桥杯试题》《LeetCode刷题笔记》《实训项目》《C》《Linux》《算法》 &#x1f31d;每一个不曾起舞的日子&#xff0c;都是对生命的辜负 目录 前言 1.List迭代器 2.适…

0004.电脑开机提示按F1

常用的电脑主板不知道什么原因&#xff0c;莫名其妙的启动不了了。尝试了很多方法&#xff0c;没有奏效。没有办法我就只能把硬盘拆了下来&#xff0c;装到了另一台电脑上面。但是开机以后却提示F1&#xff0c;如下图&#xff1a; 根据上面的提示&#xff0c;应该是驱动有问题…

力扣645.错误的集合

一点一点地刷&#xff0c;慢慢攻克力扣&#xff01;&#xff01; 王子公主请看题 集合 s 包含从 1 到 n 的整数。不幸的是&#xff0c;因为数据错误&#xff0c;导致集合里面某一个数字复制了成了集合里面的另外一个数字的值&#xff0c;导致集合 丢失了一个数字 并且 有一个数…

基于springboot+vue仓库管理系统

摘要 本文介绍了一种基于Spring Boot和Vue的现代化仓库管理系统的设计与实现。仓库管理是企业运营中至关重要的一环&#xff0c;它涉及到货物的进出、库存的管理以及订单的处理等方面。为了提高仓库管理的效率和精确度&#xff0c;我们设计了这个集成了前后端技术的系统。在系统…

IntelliJ IDEA 常用快捷键一览表(通用型,提高编写速度,类结构、查找和查看源码,替换与关闭,调整格式)

文章目录 IntelliJ IDEA 常用快捷键一览表1-IDEA的日常快捷键第1组&#xff1a;通用型第2组&#xff1a;提高编写速度&#xff08;上&#xff09;第3组&#xff1a;提高编写速度&#xff08;下&#xff09;第4组&#xff1a;类结构、查找和查看源码第5组&#xff1a;查找、替换…

数据操作——缺失值处理

缺失值处理 缺失值的处理思路 如果想探究如何处理无效值, 首先要知道无效值从哪来, 从而分析可能产生的无效值有哪些类型, 在分别去看如何处理无效值 什么是缺失值 一个值本身的含义是这个值不存在则称之为缺失值, 也就是说这个值本身代表着缺失, 或者这个值本身无意义, 比如…

Spring成长之路—Spring MVC

在分享SpringMVC之前&#xff0c;我们先对MVC有个基本的了解。MVC(Model-View-Controller)指的是一种软件思想&#xff0c;它将软件分为三层&#xff1a;模型层、视图层、控制层 模型层即Model&#xff1a;负责处理具体的业务和封装实体类&#xff0c;我们所知的service层、poj…

智慧文旅一机游:科技与文化的完美结合,引领智慧文旅新潮流,智慧旅游未来已来

一、科技与文化的完美结合&#xff1a;智慧文旅一机游的核心理念 智慧文旅一机游&#xff0c;是科技与文化相融合的产物&#xff0c;它不仅代表着旅游行业的创新与发展&#xff0c;更是一种文化与科技完美结合的生活方式。一机游的核心理念在于通过先进的科技手段&#xff0c;提…

HttpServletRequest getServerPort()、getLocalPort() 、getRemotePort() 区别

getRemotePort() 、getServerPort()、getLocalPort() request.getServerPort()、request.getLocalPort() 和 request.getRemotePort() 这三个方法都是获取与HTTP请求相关的端口信息的 客户端(如浏览器)通过某个随机分配的网络连接端口(7070) 向服务器发送HTTP请求( http://exam…

Leetcode刷题笔记题解(C++):LCR 174. 寻找二叉搜索树中的目标节点

思路&#xff1a;二叉搜索树的中序遍历是有序的从大到小的&#xff0c;故得出中序遍历的结果&#xff0c;即要第cnt大的数为倒数第cnt的数 /*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeN…

嵌入式学习-网络编程-Day6

嵌入式学习-网络编程-Day6 一、思维导图 二、作业 1.基于UDP的网络聊天室&#xff08;2024.1.21号前上交&#xff09; 项目需求&#xff1a; 1.如果有用户登录&#xff0c;其他用户可以收到这个人的登录信息 2.如果有人发送信息&#xff0c;其他用户可以收到这个人的群聊信息…

读书笔记之《万物起源》:宇宙与人类的极简史

《万物起源&#xff1a;从宇宙大爆炸到文明的兴起》讲述了从大爆炸直到今日&#xff0c;约140亿年间所有重大事物的起源&#xff0c;依次覆盖了量子力学&#xff0c;天体物理学&#xff0c;化学&#xff0c;行星科学&#xff0c;地质学&#xff0c;生物学和人类历史等等学科。 …

Spring第七天(AOP)

简介 AOP(Aspect Oriented Programing)面向切面编程&#xff0c;一种编程范式&#xff0c;指导开发者如何组织程序结构 作用 在不惊动原始设计的基础上为其进行功能增强 Spring理念&#xff1a;无入侵式/无侵入式 基本概念 连接点(JoinPoint) : 程序执行过程中的任意位置&a…

Linux:软硬链接的概念与应用

文章目录 软链接和硬链接软链接的应用场景硬链接的应用场景当前目录和上级目录软硬链接目录和文件的问题 总结 本篇要探讨的主题是关于软硬链接的概念 在Linux系统链接文件中有两种&#xff0c;一种是硬链接&#xff0c;一种是软链接&#xff0c;那么本篇就基于上述的两种链接…

IDEA的database使用

一、数据据库 在使用database之前&#xff0c;首先你的电脑要安装好了数据库并且启动。 MySQL卸载手册 链接&#xff1a;https://pan.baidu.com/doc/share/AVXW5SG6T76puBOWnPegmw-602323264797863 提取码&#xff1a;hlgf MySQL安装图解 链接&#xff1a;https://pan.baidu.…