使用自定义旋转木马进行分页
Getting pagination to work with custom carousel
我正试图创建一个带有分页的转盘(demo)。当用户单击底部的块时,它应该循环到相应的图像。下面的代码就是我目前拥有的代码。小心控制台的胡言乱语。现在我正在确定用户是否在可见块之后或之前单击。
//grab the width and calculate left value
var item_width = $('#slides li').outerWidth();
var left_value = item_width * (-1);
//if user clicks on pagination block
$('#pagination ul li').click(function() {
var $this = $(this);
var temp = $(this).index() + 1;
var current = $('#pagination li a.active').parent().index() + 1; // console.log(current + " : " + temp );
if (current <= temp) {
// get difference of temp and current (temp - current)
var jump = Math.abs(temp - current);
//get the right position
var left_indent = parseInt($('#slides ul').css('left')) - item_width;
//slide the item
$('#slides ul').animate({'left' : left_indent}, 300, function () {
//active pagination
$('#pagination li a.active').removeClass('active');
$this.children().addClass('active');
//move the first item and put it as last item
$('#slides li:last').after($('#slides li:first'));
//set the default item to correct position
$('#slides ul').css({'left' : left_value});
//debugging nonsense
console.log( "left_indent: " + left_indent + "px" + "'n" + "left_value: " + left_value + "px" + "'n" + "current slide: " + current + "'n" + "future slide: " + temp + "'n" + "difference: " + jump);
});
} else if (current >= temp) {
// get difference of temp and current (temp - current)
var jump = Math.abs(temp - current);
//get the right position
var left_indent = parseInt($('#slides ul').css('left')) + item_width;
//slide the item
$('#slides ul').animate({'left' : left_indent}, 300,function(){
//active pagination
$('#pagination li a.active').removeClass('active');
$this.children().addClass('active');
//move the last item and put it as first item
$('#slides li:first').before($('#slides li:last'));
//set the default item to correct position
$('#slides ul').css({'left' : left_value});
//debugging nonsense
console.log( "left_indent: " + left_indent + "px" + "'n" + "left_value: " + left_value + "px" + "'n" + "current slide: " + current + "'n" + "future slide: " + temp + "'n" + "difference: " + jump);
});
}
});
我已经尝试过获取温度和电流的差异:
var jump = Math.abs(temp - current);
然后将两个相乘
$('#slides ul').animate({'left' : left_indent * jump}, 300, function () {
$('#slides ul').css({'left' : left_value * jump});
通过跳跃,但它不起作用。我跳了几下就有空位了。
我似乎不能针对left_indent、left_value和分页之间的关系。感谢您的帮助。
jsFiddle:http://jsfiddle.net/hyTeq/
你的小提琴里有很多代码,所以我创建了一个例子,你可以做些什么来展示你的图片(这有望让你开始…):
Fiddle示例
$(document).ready(function(){
$('.container div:first').addClass('active');
$('.container div:not(.active)').hide();
$('.pagination div').click(function(){
//Get the index of pagination and store it in VAR
var getPaginationIndex = $(this).index();
//alert(getPaginationIndex);
$('.active').hide().removeClass('active');
//get div and apply stored index of clicked pagination
//and show it...
$('.container div').eq(getPaginationIndex).show().addClass('active');
});
});
相关文章:
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 知道为什么我的旋转木马不会自动更改图片吗
- 如何通过引用var Using DataTables来进行分页或排序
- 使用CSS或JavaScript计算分页符的数量
- DataTables-创建自定义分页样式(加载更多样式)
- 禁用旋转木马中的下一个按钮和上一个按钮
- 使用ajax的服务器端分页&jQuery
- 分页:如何用AJAX加载第一个页面
- dataTables-如何自定义分页类型以显示最后一个页码后面的省略号,
- 不带jquery的全屏分页
- 更改组合框分页后,getValue和getRawValue返回相同的值
- 引导程序旋转木马未显示在页面上
- 如何将 .owl 分页移到主 owl 包装器之外?猫头鹰旋转木马2.
- 带有返回页首功能的旋转木马Next
- 如何使用jquery在旋转木马上隐藏和显示页脚
- 数据表在应用分页之前旋转并加载整个数据集
- 带分页的引导旋转木马-当使用旋转木马控件时,当前幻灯片在导航中不活动
- 猫头鹰旋转木马自定义图像预览分页不工作
- 使用自定义旋转木马进行分页
- 不同的项目活动的引导旋转木马在每个页面上