Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【功能建议】希望自动滚动的全屏海报加入两个按钮,实现“上一页”,“下一页”的功能 #56

Open
Junt62 opened this issue May 29, 2024 · 2 comments

Comments

@Junt62
Copy link

Junt62 commented May 29, 2024

希望自动滚动的全屏海报加入两个按钮,实现“上一页”,“下一页”的功能

@JsaRut
Copy link

JsaRut commented Jun 2, 2024

这个功能我也想了很久,但何苦自己的JS实在...

@jqtmviyu
Copy link

main.js 211行左右, 也就是 setInterval 函数结束,

添加以下代码: 鼠标滑动超过50像素, 左滑下一张, 右划上一张, 为了效果比较好, 把上面定时器的8000即8秒改为15000即15比较好.

// 鼠标按住滑动事件
    $('.misty-banner-body').on('mousedown', function(event) {
      console.log(event);
      if (event.button === 0) { // 左键按下
        let startX = event.clientX;
        let endX;

        $(document).on('mousemove', moveHandler);
        $(document).on('mouseup', upHandler);

        function moveHandler(event) {
          endX = event.clientX;
        }

        function upHandler(event) {
          $(document).off('mousemove', moveHandler);
          $(document).off('mouseup', upHandler);

          if (endX !== undefined) {
            console.log("endX , startX",endX , startX);
            if (endX - startX >= 50) {
              index -= index == 0 ? -($(".misty-banner-item").length -1) : 1
            } else if (endX - startX <= -50) {
              index += index + 1 == $(".misty-banner-item").length ? -index : 1
            } else {
              return
            }
            $(".misty-banner-body").css("left", -(index * 100).toString() + "%")
            $(".misty-banner-item.active").removeClass("active")
            let id = $(".misty-banner-item").eq(index).addClass("active").attr("id")
            $(".misty-banner-logo.active").removeClass("active")
            $(`.misty-banner-logo[id=${id}]`).addClass("active")
          }
        }
      }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants