项目滑块不工作
items sliders not working
我的html代码有问题,问题是我试图创建一个项目滑块,如果这就是它的名字,在我的情况下,我有9个项目,我只想显示其中的5个,当有人点击矩形时,它会向左滑动,向他显示剩下的3个品牌,但每次我试图这样做时,都没有发生任何事情,有关更多解释,请查看我的代码:
<div id="tf-clients" class="text-center">
<div class="overlay">
<div class="container">
<div class="section-title center">
<h2>Some of <strong>our Clients</strong></h2>
<div class="line">
<hr>
</div>
</div>
<div id="clients" class="owl-carousel owl-theme" style="opacity: 1; display: block;">
<div class="owl-wrapper-outer autoHeight" style="height: 121px;"><div class="owl-wrapper" style="width: 3192px; left: 0px; display: block;"><div class="owl-item" style="width: 228px;"><div class="item">
<img src="img/client/01.png">
</div></div><div class="owl-item" style="width: 228px;"><div class="item">
<img src="img/client/02.png">
</div></div><div class="owl-item" style="width: 228px;"><div class="item">
<img src="img/client/03.png">
</div></div><div class="owl-item" style="width: 228px;"><div class="item">
<img src="img/client/04.png">
</div></div><div class="owl-item" style="width: 228px;"><div class="item">
<img src="img/client/05.png">
</div></div><div class="owl-item" style="width: 228px;"><div class="item">
<img src="img/client/06.png">
</div></div><div class="owl-item" style="width: 228px;"><div class="item">
<img src="img/client/07.png">
</div></div></div></div>
<div class="owl-controls clickable"><div class="owl-pagination"><div class="owl-page active"><span class=""></span></div><div class="owl-page"><span class=""></span></div></div></div></div>
</div>
</div>
</div>
正如你所看到的,这是我的代码,它有9个图像,我创建了一个span标签,以便创建一个矩形,所以当我点击span时,它会通过向左滑动来显示其他隐藏的图像,但它似乎不起作用。如果我做错了什么,请帮我一把,我们将不胜感激。
我最近刚刚和类似的人一起练习。这就是我想到的,看看它是否有帮助:
http://jsfiddle.net/v3kLwh0o/
HTML:
<div class="slider-wrapper">
<div class="arrows">
<div class="left"><i class="fa fa-chevron-left fa-lg"></i></div>
<div class="right"><i class="fa fa-chevron-right fa-lg"></i></div>
</div>
<ul class="slides">
<li class="slide one"></li>
<li class="slide two"></li>
<li class="slide three"></li>
<li class="slide one"></li>
</ul>
</div>
CSS:
.slider-wrapper {
margin: auto;
margin-top: 50px;
width: 720px;
height: 400px;
overflow: hidden;
background-color: black;
}
.slider-wrapper > .slides {
list-style: none;
margin: 0;
padding: 0;
width: 2880px; /* 720*4(pictures) */
height: 400px;
}
.one { background-color: blue; }
.two { background-color: green; }
.three { background-color: red; }
.slider-wrapper > .slides .slide {
width: 720px; /* 720px */
height: 400px; /* 400px */
float: left;
}
.slider-wrapper > .arrows {
margin: 170px 0; /* (400-60[height of arrow container])/2 */
position: absolute;
width: 720px;
}
.slider-wrapper > .arrows > .left, .slider-wrapper > .arrows > .right {
height: 60px;
width: 50px;
background-color: gray;
padding: 20px 0; /* (60-20[height of arrow])/2 */
color: white;
text-align: center;
}
.slider-wrapper > .arrows > .left:hover, .slider-wrapper > .arrows > .right:hover {
background-color: black;
cursor: pointer;
}
.slider-wrapper > .arrows > .left { float: left; }
.slider-wrapper > .arrows > .right { float: right; }
JS:
// Set quantified variables
var width = 720;
var animationSpeed = 1000;
var slideCount = 1;
// Set variables to cache the DOM tree parts that are needed (makes performance faster since the program doesn't have to go through the entire tree everytime)
var $leftArrow = $('.arrows > .left');
var $rightArrow = $('.arrows > .right');
var $slider = $('.slider-wrapper > .slides');
var $slides = $slider.find('.slide');
// Runs when the left arrow is clicked
$leftArrow.click(function() {
$slider.animate({'margin-left':'-='+width}, animationSpeed, function() {
// After the animation ends, increase counter and check to see if its on the last image
slideCount++;
if (slideCount == $slides.length) {
slideCount = 1;
$slider.css('margin-left','0');
}
// console.log("Left: " + slideCount);
});
});
// Runs when the right arrow is clicked
$rightArrow.click(function() {
// Check to see if slider is on the first image (which it is initially)
// If it is, change the left margin of the slider to (number of images - 1) * width * -1 (i.e. margin-left of the last image)
var firstImageCheck = function() {
if (slideCount == 1) {
slideCount = $slides.length;
lastPicMargin = width * ($slides.length-1) * -1;
$slider.css('margin-left', lastPicMargin);
}
}
firstImageCheck();
$slider.animate({'margin-left':'+='+width}, animationSpeed, function() {
// After the animation ends, decrease counter and check to see if its on the first image
slideCount--;
firstImageCheck();
// console.log("Right: " + slideCount);
});
});
相关文章:
- 让typescript与facebook登录为Angular 2项目工作
- 引导轮播,修改为显示多个项目.无法正常工作的火狐和IE
- 当控制台不在't在chrome中打开,有些项目不再可点击(有些js调用停止工作)
- 我正试图获得一个带有复选框的多选下拉列表,在填充项目和获得所有选中的工作时遇到了一些问题
- javascript函数没有'不能在MVC项目下工作
- simple{{}}不在angularJS项目中工作
- 项目获胜'我不在火狐工作
- 单击的第二个项目无法正常工作
- 轨道:-位置.Href 不在项目中工作
- 离子项目,不是在手机上工作,而是在开发过程中工作
- 在angular Webpack工作流演示项目中导入angular Webpack
- 循环时更改数组中项目的样式是't工作
- 我可以'我不能让这个JFidddle代码在我的项目中工作
- 占位符文本在IE中不带项目符号.使用chrome可以很好地工作
- 了解eclipse项目的性质和web开发的工作流程
- 当项目停止在.NET中运行时,有没有办法阻止web方法工作
- 我试图创建一个简单的angularjs项目,但ng-view不工作
- 我需要做些什么才能让账户进入我的流星项目工作
- CheckBoxList检查所有项目,点击只工作一次
- 我的Bootstrap模式锚不是从一个菜单(导航栏)的行项目内工作