1
我在嘗試使我的JQuery滑塊響應時遇到問題(如果我調整窗口大小的一半被裁剪掉),事情是,使用視口和媒體查詢我網站上的其他所有內容都是響應式,只是滑塊不是。JQuery滑塊響應式設計故障
這裏是我的jsfiddle https://jsfiddle.net/Syystole/4r4qnojo/3/
HTML
<style>
img {max-width: 100%}
.side-by-side{
display: flex;
}
</style>
<body>
<div class="WrapperPage">
<section id="slider">
<ul class="mySlide">
<li><img src="http://lorempixel.com/400/200/sports" alt="Slider Image"/></li>
<li><img src="http://lorempixel.com/400/200/sports" alt="Slider Image"/></li>
<li><img src="http://lorempixel.com/400/200/sports" alt="Slider Image" /></li>
<li><img src="http://lorempixel.com/400/200/sports" alt="Slider Image" /></li>
</ul>
<span class="button back">Back</span>
<span class="button next">Next</span>
</section>
</div>
</body>
</html>
JS
var sliderList;
$(function() {
var sliderWrapper = $("#slider");
sliderList = sliderWrapper.children("ul");
var sliderItems = sliderList.children("li");
var count = 1;
var sliderItems = $('ul.mySlide > li').length;
var sliderDuration = 1000;
var countLimitReached = "";
function animateSlider(direction, duration, countLimitReached) {
if (direction === "+") {
count--;
if(countLimitReached == "start"){
sliderList.animate({
"margin-left": "-=2400px"
}, duration);
count = 4;
return;
} else
{
sliderList.animate({
"margin-left": "+=800px"
}, duration);
}
}
else if (direction === "-") {
count++;
if(countLimitReached == "end"){
sliderList.animate({
"margin-left": "+=2400px"
}, duration);
count = 1;
return;
} else
{
sliderList.animate({
"margin-left": "-=800px"
}, duration);
}
}
}
function checkCount(count, sliderItems){
if(count === sliderItems){
return "end";
}
else if(count == 1){
return "start";
}
return "";
}
$(".button").on('click', function() {
countLimitReached = checkCount(count, sliderItems);
if ($(this).hasClass("back")) {
animateSlider("+", sliderDuration, countLimitReached);
} else {
animateSlider("-", sliderDuration, countLimitReached);
}
countLimitReached = "";
});
});
CSS
#slider {
margin: 0 auto;
width: 82%;
overflow:hidden;
}
#slider ul {
list-style: none;
width: 3500px;
margin: 0;
padding: 0;
}
#slider li{
float: left;
width: 800px;
}
img{
width:100%;
}
.button {
font-family: Arial, sans-serif;
font-size: 20px;
display: block;
padding: 20px;
border: 1px solid #ccc;
}
.back {
float: left;
}
.next {
float: right;
}
我認爲你可以代替這個https://jsfiddle.net/tLhs1v59/ –
我想我的代碼來弄明白儘管使用你的代碼 – Syystole