javascript-从头开始制作jquery轮播
作者:互联网
我知道这里有很多关于jquery图像轮播的问题,但它们都涉及插件.我想从头开始.这是一个非常简单的按钮,有2个按钮,一个向左,一个向右.当您单击左按钮时,包含所有图像的整个容器的位置将移至左侧,而右侧将使其移至右侧.
这就是我到目前为止所拥有的…现在的问题是只有向左按钮有效. (仅当您将图像向左滑动一次时,右键才起作用)我也希望它在所有图像上设置动画,并在到达图像集的末尾时转到最后一个图像
JS:
total_entries = $("image-entry").length;
var current_index = 0;
var slider_entries = $('#slider-entries');
$('#home-slider #left').click(function(){
go_to_index(current_index-1);
return false;
});
$('#home-slider #right').click(function(){
go_to_index(current_index+1);
return false;
});
var go_to_index = function(index){
if(index < 0)
index = total_entries - 1;
if(index > total_entries - 1)
index = 0;
if(current_index == index)
return;
var left_offset = -1 * index * 720;
slider_entries.stop().animate({"left": left_offset}, 250);
//description_container.stop().animate({"left":left_offset}, 250);
current_index = index;
};
HTML:
<div id="slider">
<div id="slider-entries">
<div class="image-entry">
<img src="http://placekitten.com/720/230" />
</div>
<div class="image-entry">
<img src="http://placedog.com/720/230" />
</div>
<div class="image-entry">
<img src="http://placedog.com/720/230" />
</div>
</div>
</div>
每张图片的总宽度为720px
滑块条目的总数为
谢谢
解决方法:
您对total_entries变量有疑问.
首先,您需要在前面添加一个“ var”,以定义它是一个新变量.
其次,您忘记了“.” (点)以在HTML代码中搜索该类.
您的第一行应该是:
var total_entries = $(".image-entry").length;
希望它有用;-)
标签:image-processing,javascript,jquery 来源: https://codeday.me/bug/20191208/2091817.html