gpt4 book ai didi

javascript - 关闭 Glide.js 轮播上的拖动

转载 作者:行者123 更新时间:2023-11-28 17:32:24 31 4
gpt4 key购买 nike

我想通过拖动关闭更改幻灯片,并仅使用“上一页”-“下一页”按钮循环浏览幻灯片。我设置了 swipeThreshold: false,如文档 https://glidejs.com/docs/options/ 中所述。但我仍然可以拖动幻灯片,正如您在下面的代码中看到的那样。如何禁用幻灯片拖动?

function coverflow(i, el) {
el.removeClass('pre following')
.nextAll()
.removeClass('pre following')
.addClass('following')
.end()
.prevAll()
.removeClass('pre following')
.addClass('pre');
}

$('#Glide').glide({
type: 'carousel',
startAt: 1,
animationDuration: 500,
paddings: '25%',
swipeThreshold: false,
afterInit: function (event) {
coverflow(event.index, event.current);
},
afterTransition: function (event) {
coverflow(event.index, event.current);
}
});
.box {
width: 100%;
height: 60vh;
border-radius: 12px;
}
.glide__wrapper {
padding: 15vh 0;
}
.glide__track {
overflow: visible;
height: 60vh;
}
.glide__slide {
-webkit-transition: all 200ms ease;
transition: all 200ms ease;
-webkit-transform-origin: 50% 50%;
transform-origin: 50% 50%;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.glide__slide.active {
-webkit-transform: scale(1.02);
transform: scale(1.02);
}
.glide__slide.pre {
-webkit-transform: perspective(50em) rotateY(15deg);
transform: perspective(50em) rotateY(15deg);
}
.glide__slide.following {
-webkit-transform: perspective(50em) rotateY(-15deg);
transform: perspective(50em) rotateY(-15deg);
}
.glide--horizontal .glide__bullets {
bottom: 25%;
}
body {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
<html >
<head>
<meta charset="UTF-8">
<title>Coverflow carousel with Glide.js</title>

<link rel='stylesheet prefetch' href='https://cdn.rawgit.com/jedrzejchalubek/glidejs/8eabfbb9/dist/css/glide.core.min.css'>
<link rel='stylesheet prefetch' href='https://cdn.rawgit.com/jedrzejchalubek/glidejs/8eabfbb9/dist/css/glide.theme.min.css'>



</head>

<body>

<div class="glide" id="Glide">
<div class="glide__arrows">
<button class="glide__arrow prev" data-glide-dir="<">prev</button>
<button class="glide__arrow next" data-glide-dir=">">next</button>
</div>
<div class="glide__wrapper">
<ul class="glide__track">
<li class="glide__slide">
<div class="box" style="background-color: #77A7FB"><img>Srikanth</div>
</li>
<li class="glide__slide">
<div class="box" style="background-color: #FBCB43"></div>
</li>
<li class="glide__slide">
<div class="box" style="background-color: #34B67A"></div>
</li>
<li class="glide__slide">
<div class="box" style="background-color: #95a5a6"></div>
</li>
<li class="glide__slide">
<div class="box" style="background-color: #9b59b6"></div>
</li>
</ul>
</div>
<ul class="glide__bullets"></ul>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script src='https://cdn.rawgit.com/jedrzejchalubek/glidejs/8eabfbb9/dist/glide.min.js'></script>



</body>
</html>

最佳答案

您正在使用 ^2.0.0 版本的 Glide.js。请引用存档2.0.0 docs .

dragDistance 选项设置为 false

$('#Glide').glide({
type: 'carousel',
startAt: 1,
animationDuration: 500,
paddings: '25%',
dragDistance: false,
afterInit: function (event) {
coverflow(event.index, event.current);
},
afterTransition: function (event) {
coverflow(event.index, event.current);
}
});

附注:有两个选项用于控制拖动:

  • dragDistance - 控制鼠标拖动
  • touchDistance - 控制手指触摸拖动

关于javascript - 关闭 Glide.js 轮播上的拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50001997/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com