0
我試圖讓我的滑塊在觸摸屏上工作,所以我找到了一個名爲touchSwipt的插件。這裏是多少有點像我想要的演示的鏈接。觸摸滑塊不起作用
,這是我看到了它
它的工作原理,如果我只是複製和粘貼演示的HTML,但是當我嘗試添加我自己的東西的網站它不起作用。 這裏是JSFiddle。 JSFIDDLE
這裏是我的html
<div class="slider-wrapper">
<div class="slider">
<div id="test" class="box">
<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>
</ul>
</div>
</div>
<ul class="triggers">
<li><img src="http://s25.postimage.org/hj22mxdgr/border_box.png"> </li>
<li><img src="http://s25.postimage.org/hj22mxdgr/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("http://s25.postimg.org/8cjrzn88b/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;
}
,這是我的Jquery
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);
}
$("#test").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;
}
} else if (direction == "right") {
rotateBanners(($(".portfolio-active").index() - 1));
}
},
threshold: 0
});