Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >允许移动用户在滑块中滑动

允许移动用户在滑块中滑动
EN

Stack Overflow用户
提问于 2019-03-28 09:32:04
回答 1查看 44关注 0票数 1

我前段时间创建了一个产品滑块,但是我似乎无法解决如何让移动用户在幻灯片之间滑动。我已经设法允许PC用户使用键盘箭头,但还没有找到适用于移动用户的解决方案。

有没有JS解决方案可以做到这一点?

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$('.slider').each(function() {
    var $this = $(this);
    var $group = $this.find('.slide_group');
    var $slides = $this.find('.slide');
    var bulletArray = [];
    var currentIndex = 0;
    var timeout;

    function move(newIndex) {
      var animateLeft, slideLeft;

      advance();

      if ($group.is(':animated') || currentIndex === newIndex) {
        return;
      }

      bulletArray[currentIndex].removeClass('active');
      bulletArray[newIndex].addClass('active');

      if (newIndex > currentIndex) {
        slideLeft = '100%';
        animateLeft = '-100%';
      } else {
        slideLeft = '-100%';
        animateLeft = '100%';
      }

      $slides.eq(newIndex).css({
        display: 'flex',
        left: slideLeft
      });
      $group.animate({
        left: animateLeft
      }, function() {
        $slides.eq(currentIndex).css({
          display: 'none'
        });
        $slides.eq(newIndex).css({
          left: 0
        });
        $group.css({
          left: 0
        });
        currentIndex = newIndex;
      });
    }

    function advance() {
      clearTimeout(timeout);
      timeout = setTimeout(function() {
        if (currentIndex < ($slides.length - 1)) {
          move(currentIndex + 1);
        } else {
          move(0);
        }
      }, 25000);
    }

    $('.next_btn').on('click', function() {
      if (currentIndex < ($slides.length - 1)) {
        move(currentIndex + 1);
      } else {
        move(0);
      }
    });

    $('.previous_btn').on('click', function() {
      if (currentIndex !== 0) {
        move(currentIndex - 1);
      } else {
        move(3);
      }
    });

    $.each($slides, function(index) {
      var $button = $('<a class="slide_btn">&bull;</a>');

      if (index === currentIndex) {
        $button.addClass('active');
      }
      $button.on('click', function() {
        move(index);
      }).appendTo('.slide_buttons');
      bulletArray.push($button);
    });

    advance();
  });
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
slider-wrapper,
.slider-wrapper-2 {
    position:      relative;
    margin-bottom: 150px;
}

.slider,
.slider-2 {
    margin:    auto;
    max-width: 70vw;
    position:  relative;
    margin-bottom: 50px;
    height: 50vh;
}

.slide_viewer,
.slide_viewer {
    height:   60vh;
    overflow: hidden;
    position: relative;
}

.slide_group,
.slide_group-2 {
    height:   50vh;
    position: relative;
    width:    100%;
}

.slide,
.slide-2 {
    display:        none;
    height:         100%;
    position:       absolute;
    width:          100%;
    flex-direction: row;
}

.slider-content-left {
    width:           50%;
    height:          100%;
    background:      white;
    display:         flex;
    justify-content: center;
    align-items:     center;
}

.product-image {
    background-size:     contain;
    background-position: center;
    background-repeat:   no-repeat;
    height:              70%;
    width:               70%;
    cursor: pointer;
    position: relative;
}

.product-image .material-icons{
    position: absolute;
    top: 0;
    right: 0;
    padding: 5px;
    background: whitesmoke;
    border: 1px solid grey;
}

.product-image.P60{
    background-image: url('Images/Products/R-Series/P60/OL315_2.jpg');
}

.product-image.XW1{
    background-image: url('Images/Products/R-Series/XW1/xw1.png');
}

.slider-content-right {
	width:       50%;
	height:      100%;
	display:     flex;
	align-items: center;
}

.product-details {
	height:         auto;
	width:          90%;
	display:        flex;
	flex-direction: column;
	margin:         auto;
}

.product-details h2 {
	text-align: left;
	margin:      0;
	color: black;
}

.product-details ul{
    padding: 17.5px;
}

.slide:first-child,
.slide-2:first-child {
    display: flex;
}

.slide_buttons,
.slide_buttons-2 {
    left:       100px;
    position:   absolute;
    right:      100px;
    text-align: center;
}

a.slide_btn,
a.slide_btn2 {
    color:              #474544;
    font-size:          42px;
    margin:             0 0.175em;
    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition:    all 0.4s ease-in-out;
    -ms-transition:     all 0.4s ease-in-out;
    -o-transition:      all 0.4s ease-in-out;
    transition:         all 0.4s ease-in-out;
}

.slide_btn.active,
.slide_btn2.active,
.slide_btn:hover,
.slide_btn2:hover {
    color:  #1160AB;
    cursor: pointer;
}

.directional_nav, .directional_nav-2 {
    margin:    0 auto;
    max-width: 940px;
    top: -340px;
}

.previous_btn,
.next_btn,
.previous_btn-2,
.next_btn-2 {
    margin:   auto;
    position: absolute;
    top:      0;
    bottom:   0;

    cursor:             pointer;
    height:             65px;
    opacity:            0.5;
    -webkit-transition: opacity 0.4s ease-in-out;
    -moz-transition:    opacity 0.4s ease-in-out;
    -ms-transition:     opacity 0.4s ease-in-out;
    -o-transition:      opacity 0.4s ease-in-out;
    transition:         opacity 0.4s ease-in-out;
    width:              65px;
}

.previous_btn,
.previous_btn-2 {
    left:     50px;
}

.next_btn,
.next_btn-2 {
    right:    100px;
}

.previous_btn:hover,
.next_btn:hover,
.previous_btn-2:hover,
.next_btn-2:hover{
    opacity: 1;
}
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<div class="slider-wrapper">
    <div class="slider">
        <div class="slide_viewer">
            <div class="slide_group">
                <div class="slide">
                    <div class="slider-content-left">
                        <div class="product-image P60" onclick="openModal();currentSlide(1)">
                            <i class="material-icons">zoom_out_map</i>
                        </div>
                    </div>
                    <div class="slider-content-right">
                        <div class="product-details">
                            <h2>P60R / P50R - Panniers</h2>
                            <p><i>Attachment: Strap-On</i></p>
                            <p><b style="margin-left: -15px;"><i>"Oxford's P60 Panniers were the best performing set in the test.<br>Use the internal dry bags and you'll have all the panniers you'll ever need."</b></i><br><br> RiDE - May 2017. <br><i>Read the full review <a href="#" style="text-decoration:underline;"> here</a></i></p>
                            <p>An extremely versatile set of panniers which provide a huge 60/50 litres of storage. Suitable for almost any bike, but perfect for naked bikes, tourers and sports tourers and for those that need a lot of flexibility in their luggage. Comes with ALL the necessary attachment equipment for a wide variety of bikes.</p>
                            <ul>
                                <li>Heat resistant base in case of momentary contact with the exhaust</li>
                                <li>Large top opening aand 360 degree opening zips for easy access to contents</li>
                                <li>Rubberised side panels helps to protect the paintwork</li>
                                <li>Internal net pocket</li>
                                <li>7 point secure fitting system</li>
                                <li>Made from tough ripstop Nylon</li>
                            </ul>
                            <h4 class="h4black">50L - £159.99<br> 60L - £169.99</h4>
                        </div>
                    </div>
                </div>

                <div class="slide">
                    <div class="slider-content-left">
                        <div class="product-image XW1" onclick="openModal14();currentSlide14(1)">
                            <i class="material-icons">zoom_out_map</i>
                        </div>
                    </div>
                    <div class="slider-content-right">
                        <div class="product-details">
                            <h2 style="color:black">XW1 - Waist bag 1.5L</h2>
                            <ul>
                                <li>1.5 litre capacity</li>
                                <li>Reflective logo and trim</li>
                                <li>Main compartment and front pocket</li>
                                <li>Padded back section for added comfort</li>
                                <li>Adjustable waist strap ( up to 40")</li>
                                <li>Material: 600D polyester and Ripstop fabric </li>
                                <li>Main compartment dimensions W19cm x H13cm</li>
                            </ul>
                            <h4 class="h4black">£14.99</h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="slide_buttons"></div>

    <div class="directional_nav">
        <div class="previous_btn" title="Previous">
            <i class="material-icons">arrow_back_ios</i>
        </div>
        <div class="next_btn" style="text-align:right;" title="Next">
            <i class="material-icons">arrow_forward_ios</i>
        </div>
    </div>
</div>

如果有什么简单的方法可以让手机变得友好,我很想知道,到目前为止,我的研究还没有找到任何东西。

提亚

EN

回答 1

Stack Overflow用户

发布于 2019-03-28 09:48:35

您可以在幻灯片上使用触摸事件,touchstart用于获取滑动的起点,touchend用于结束,touchmove用于在滑动时移动幻灯片

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

https://stackoverflow.com/questions/55394216

复制
相关文章
android自定义滑块解锁,android 滑动解锁
通过android自定义View实现横向的滑动解锁,1、滑动到中间会自动返回到原始的位置,2、滑动到底部会自动解锁,会触发解锁的回调;首先看效果图如下:
全栈程序员站长
2022/09/07
1.9K0
android自定义滑块解锁,android 滑动解锁
win10 uwp 动画移动滑动条的滑块
堆栈网小伙伴问如何点击滑动条的时候,可以通过动画将滑块从原来的坐标移动到用户点击的坐标,同时用户拖动的时候不做动画 在后台代码添加两个事件,一个是按下,一个抬起,通过按下和抬起判断坐标可以知道用户是点击还是拖动。然后用上一个值和当前的值做动画就可以。
林德熙
2022/08/04
6250
滑动窗口模式在 TPS 限制中的应用
在我们构建和优化高并发系统时,往往会遇到需要对服务的请求数进行限制的需求。这是因为无论服务多么强大,其处理能力总是有限的。超出处理能力的请求可能会导致服务过载,进而影响到整个系统的稳定性。对于这种情况,我们可以采用限流的方式来控制进入服务的请求数量,以保证服务的稳定运行。其中,滑动窗口模式是一种常见的限流算法。
运维开发王义杰
2023/08/15
3130
滑动窗口模式在 TPS 限制中的应用
pyppeteer对于iframe中的滑块
import asyncio import time import numpy, random import pyppeteer async def main(): ip = "xxxxxx" #代理ip port = "xxxx" #代理端口 browser = await pyppeteer.launch({'headless': False, 'args': [
小小咸鱼YwY
2020/12/21
2.8K0
PHP FFI 允许在 PHP 脚本中嵌入原始 C 代码
Zend 的 Dmitry Stogov 通过允许 PHP 执行嵌入式 C 代码扩展了 PHP 的领域。 这将允许完全访问本地 C 函数,变量以及数据结构。
猿哥
2019/07/25
1K0
Python Java 滑块识别-通杀滑块「建议收藏」
在写爬虫的时候,经常会遇到滑块问题,很多次都想过尝试如何攻破滑块,但是每次都没成功,除了最开始的极验滑块,当时通过原图和滑块图的对比,能够得出缺口坐标,但是随着极验、网易、腾讯滑块的更新,已经不能够找到原图了,下面给出滑块通杀的解决方案。
全栈程序员站长
2022/11/07
2.3K0
MySQL允许在唯一索引字段中添加多个NULL值
我们可以看出,此约束不适用于除BDB存储引擎之外的空值。对于其他引擎,唯一索引允许包含空值的列有多个空值。
Java那些事儿
2020/07/21
10.1K0
MySQL允许在唯一索引字段中添加多个NULL值
滑块混淆代码
顺带一提,大概花了一天半学的ast,掌握的没那么高级...抱着实现就行的心态...所以代码不够简洁,语法不够高级请见谅...
懒py夏洛
2022/06/02
1.3K0
滑块混淆代码
Flutter 流体滑块
在本文中,我们将**探讨Flutter中的Fluid Slider。**我们还将在flutter应用程序中使用flutter_fluid_slider包来实现流体滑块和属性的演示程序。
老孟Flutter
2021/05/11
11.7K0
Flutter 流体滑块
AntUI滑块Sliders
浅色分页器 <style>.demo-swiper.swiper-container {    height: 150px;    overflow: hidden;    margin: 0 10px;    padding-top: 10px; }.demo-swiper .swiper-slide {    line-height: 140px;    text-align: center;    background: #108EE9;    color: #ffffff; }</style><di
爱知汇
2020/10/10
2.4K2
拖动滑块验证
效果: 源码: <!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>drag</title> <style> /
阿超
2022/08/21
3.3K0
拖动滑块验证
Android 中 View 的滑动
Android View控件的滑动是 Android 的一个重要内容。在 View 需要变换位置时,为其添加适当的滑动效果,获得更好的用户体验,下面来看一下怎样去实现 View 的滑动:
指点
2019/01/18
9410
Android 中 View 的滑动
我们应该允许大佬在大会上睡觉
今天,一张图刷爆了朋友圈。 姑且将之命名为『雷军看周鸿祎睡觉图』。 在大会上睡觉的听众何止周鸿祎。扪心问问自己,你有没有在参加大会睡着的经历,尤其是『大会』!这张照片之所以如此火,有几点: 1、雷军
罗超频道
2018/04/27
9050
我们应该允许大佬在大会上睡觉
小小滑块大大学问,你真的会用滑块了吗?
以下内容由摹客团队翻译整理,仅供学习交流,摹客iDoc是支持智能标注和切图的产品协作设计神器。
奔跑的小鹿
2019/06/24
2K0
豆瓣登录滑块分析
还有前几天,一个读者给我发了个js文件。。我发现那个js文件是我以前写的。是以前免费分享出去的,,他说是在githup上找的。。。。
懒py夏洛
2022/06/02
1.4K0
豆瓣登录滑块分析
Python Qt GUI设计:QSlider滑动条类(基础篇—16)
QSlider控件提供了一个垂直或水平的滑动条,滑动条是一个用于控制有界值的典型控件,它允许用户沿水平或垂直方向在某一范围内移动滑块,并将滑块所在的位置转换成一个合法范围内的整数值。
不脱发的程序猿
2021/10/25
2.2K0
Python Qt GUI设计:QSlider滑动条类(基础篇—16)
自动滑块验证码识别_滑块验证码原理
有爬虫,自然就有反爬虫,就像病毒和杀毒软件一样,有攻就有防,两者彼此推进发展。而目前最流行的反爬技术验证码,为了防止爬虫自动注册,批量生成垃圾账号,几乎所有网站的注册页面都会用到验证码技术。其实验证码的英文为 CAPTCHA(Completely Automated Public Turing test to tell Computers and Humans Apart),翻译成中文就是全自动区分计算机和人类的公开图灵测试,它是一种可以区分用户是计算机还是人的测试,只要能通过 CAPTCHA 测试,该用户就可以被认为是人类。由此也可知道激活成功教程滑块验证码的关键即是让计算机更好的模拟人的行为,这也是激活成功教程的难点所在。(注:本文18年所作,仅作参考)
全栈程序员站长
2022/11/18
3.7K0
自动滑块验证码识别_滑块验证码原理
点击加载更多

相似问题

在选择滑块滑块时禁用滑动

32

滑动滑块-滑轮控制允许在上一次滑动时滚动页面

16

SwiperJS滑动滑块禁止缩放时滑动,但允许单击缩略图

14

滑动滑块空位

310

滑动触控滑块-不滑动

14
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文