gpt4 book ai didi

jquery - 创建触摸 slider

转载 作者:行者123 更新时间:2023-11-28 11:09:47 25 4
gpt4 key购买 nike

我正在尝试让我的 slider 在触摸屏上工作。用户必须能够滑动图像。我需要它在平板电脑和手机上工作。我尝试使用 $(".portfolio-overlay").swipe 但这没有用,我不知道我是否做错了什么。

html

<div class="slider-wrapper">
<div class="slider">
<div class="portfolio-overlay">
<ul class="images">
<li>
<img width="704px" class="portfolio-active portfolio-single" src="http://s25.postimg.org/keaisiflb/mini_brown_fairy.jpg">
</li>
<li>
<img width="704px" class="portfolio-inactive portfolio-single" src="http://s25.postimg.org/xwhf4srqn/mini_blue_fairy.jpg">
</li>
<li>
<img width="704px" class="portfolio-inactive portfolio-single" src="http://s25.postimg.org/smcgdi7hr/mini_purple_fairy.jpg">
</li>
</ul>
</div>
</div>
<ul class="triggers">
<li>
<img src="images/border-box.png">
</li>
<li>
<img src="images/border-box.png">
</li>
<li>
<img src="images/border-box.png">
</li>
<li>
<img src="images/border-box.png">
</li>
<li>
<img src="images/border-box.png">
</li>
</ul>

CSS

.slider {
float: left;
height: 465px;
margin-left: auto;
margin-right: auto;
margin-top: 0;
overflow: hidden;
position: absolute;
width: 704px;
}
.images {
position:relative;
top:0px;
left:0px;
height:2660px;
}
.images li {
float:left;
position:relative;
top:0px;
left:0px;
}
.triggers {
left: 31.2%;
position: absolute;
top: 76.3%;
}
.triggers li {
float: left;
list-style: none outside none;
}
.triggers .selected {
background: url("../images/white-box.png") no-repeat scroll 0 3px rgba(0, 0, 0, 0);
}
.swipe-for-more {
left: 24.3%;
position: absolute;
top: 76.3%;
}
.control {
position:absolute;
top: 380px;
color:#fff;
cursor:pointer;
}

j查询

    var triggers = $('.triggers li');
var images = $('.images li');
var lastElem = triggers.length - 1;
var slider = $('.slider .images');
var imgWidth = images.width();
var target;

triggers.first().addClass('selected');
slider.css('width', imgWidth * (lastElem + 1) + 'px');

function sliderResponse(target) {
slider.stop(true, false).animate({
'left': '-' + imgWidth * target + 'px'
}, 300);
triggers.removeClass('selected').eq(target).addClass('selected');
}

triggers.click(function () {
if (!$(this).hasClass('selected')) {
target = $(this).index();
sliderResponse(target);
resetTiming();
}
});
$('.next').click(function () {
target = $('.triggers .selected').index();
target === lastElem ? target = 0 : target = target + 1;
sliderResponse(target);
resetTiming();
});
$('.prev').click(function () {
target = $('.triggers .selected').index();
lastElem = triggers.length - 1;
target === 0 ? target = lastElem : target = target - 1;
sliderResponse(target);
resetTiming();
});

function sliderTiming() {
target = $('.triggers .selected').index();
target === lastElem ? target = 0 : target = target + 1;
sliderResponse(target);
}
var timingRun = setInterval(function () {
sliderTiming();
}, 5000);

function resetTiming() {
clearInterval(timingRun);
timingRun = setInterval(function () {
sliderTiming();
}, 5000);
}

$(".portfolio-overlay").swipe({

swipe: function (event, direction, distance, duration, fingerCount) {
if ($(".portfolio-single").length < 1) return false;
clearTimeout(timeout);
directionVAR = direction;
if (direction == "left") {
var bannerMove = $(".portfolio-active").index() + 1
if ($(".portfolio-active").index() == ($(".portfolio-single").length - 1)) {

bannerMove = 0;
}
rotateBanners(bannerMove);
} else if (direction == "right") {
rotateBanners(($(".portfolio-active").index() - 1));
}
},
threshold: 0

});

这是我的 jsfiddle:JSFiddle

最佳答案

可能是也可能不是您需要的,但我使用 iScroll 进行触摸滑动。它可以设置为垂直或水平滚动、对齐点等。它非常灵活且可定制。也很容易设置。

http://cubiq.org/iscroll-4

http://iscrolljs.com

关于jquery - 创建触摸 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22067685/

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