单击按钮会使错误的轮播居中 (Jquery)
Clicking a button centers the wrong carousel (Jquery)
目前我有它,如果您单击任何编号按钮、下一个/上一个按钮或轮播中的图像,脚本将调整轮播以将其移动到视口的中心。但是,我注意到,如果您单击与第二个轮播关联的任何按钮,页面将一直向上滚动并调整到第一个轮播。如何获取它以调整正确的轮播?例如,按与 #2 轮播关联的任何按钮可调整 #2 轮播,或按 #3 轮播的任何按钮可调整 #3 轮播。
$(document).ready(function() {
$("#owl-demo").owlCarousel({
navigation: true,
pagination: true,
lazyLoad: true
});
});
$(document).ready(function() {
$("#owl-demo2").owlCarousel({
navigation: true,
pagination: true,
lazyLoad: true
});
});
var el = $('.owl-carousel .lazyOwl');
$('.owl-carousel, .owl-thumb-item').on('click', function(e) {
// var el = $(".lazyOwl", this);
var elOffset = el.offset().top;
var elHeight = el.height();
var windowHeight = $(window).height();
var offset;
if (elHeight < windowHeight) {
offset = elOffset - ((windowHeight / 2) - (elHeight / 2));
} else {
offset = elOffset;
}
var speed = 700;
$('html, body').animate({
scrollTop: offset
}, speed);
});
var animations = new Array();
// queue all
$(".owl-thumb-item").each(function() {
animations.push($(this));
});
// start animating
doAnimation(animations.shift());
function doAnimation(image) {
image.fadeIn("slow", function() {
// wait until animation is done and recurse if there are more animations
if (animations.length > 0) doAnimation(animations.shift());
});
}
http://jsfiddle.net/8bJUc/662/
你差点就对了!而不是:
//var el = $(".lazyOwl", this);
你应该使用这个:
var el = $(this);
http://jsfiddle.net/8bJUc/665/
跳跃"延迟"是由动画引起的。如果删除动画,它会立即显示正确的位置:
// $('html, body').animate({
// scrollTop: offset
// }, speed);
$('html, body').scrollTop(offset);
相关文章:
- MVC Jquery-按钮点击-获取if语句错误
- 点击jQuery按钮下载文件
- jquery按钮滑动切换隐藏内容和图像切换
- 设置jquery按钮,而不是php错误和成功状态
- 使用JQuery按钮更改URL#ID
- 点击jquery按钮后,是否可以添加相同的现有dom结构
- jQuery按钮事件处理程序没有't更改内容
- 登录页面中的jquery按钮
- jQuery按钮超时
- 第二次点击jQuery按钮是't开火
- 点击功能上的JQuery按钮不起作用
- jQuery按钮每2秒点击一次
- 点击jQuery按钮出现页面滚动错误
- jQuery按钮显示/隐藏类,如果存在类
- 用于多次替换图像的 Jquery 按钮
- 通过服务链接到 jQuery 按钮
- 修复jQuery按钮滑块
- JQuery 按钮单击未注册
- jQuery 按钮在值更改后首次单击时不起作用
- JQuery 按钮多次单击