Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击按钮将错误的转盘居中(Jquery)_Javascript_Jquery - Fatal编程技术网

Javascript 单击按钮将错误的转盘居中(Jquery)

Javascript 单击按钮将错误的转盘居中(Jquery),javascript,jquery,Javascript,Jquery,目前我有它,因此如果您单击任何编号按钮、下一个/上一个按钮或旋转木马中的图像,脚本将调整旋转木马以将其移动到视口的中心。但是,我注意到,如果您单击与第二个旋转木马相关联的任何按钮,页面将一直向上滚动并调整到第一个旋转木马。我如何获得它,以便调整正确的转盘?例如,按下与#2转盘相关的任何按钮可调整#2转盘,或按下#3转盘的任何按钮可调整#3转盘 $(document).ready(function() { $("#owl-demo").owlCarousel({ navigation:

目前我有它,因此如果您单击任何编号按钮、下一个/上一个按钮或旋转木马中的图像,脚本将调整旋转木马以将其移动到视口的中心。但是,我注意到,如果您单击与第二个旋转木马相关联的任何按钮,页面将一直向上滚动并调整到第一个旋转木马。我如何获得它,以便调整正确的转盘?例如,按下与#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());
  });
}
$(文档).ready(函数(){
$(“#猫头鹰演示”).owlCarousel({
导航:对,
分页:正确,
懒洋洋:没错
});
});
$(文档).ready(函数(){
$(“#owl-demo2”).owlCarousel({
导航:对,
分页:正确,
懒洋洋:没错
});
});
var el=$('.owl carousel.lazyOwl');
$('.owl carousel,.owl thumb item')。on('click',函数(e){
//var el=$(“.lazyOwl”,this);
var elOffset=el.offset().top;
var elHeight=el.height();
var windowHeight=$(window.height();
var偏移;
if(elHeight<窗高){
偏移=elOffset-((窗高/2)-(elHeight/2));
}否则{
偏移量=elOffset;
}
无功转速=700;
$('html,body')。设置动画({
滚动顶:偏移量
},速度);
});
var animations=新数组();
//全部排队
$(“.owl thumb item”)。每个(函数(){
动画。推送($(this));
});
//开始制作动画
doAnimation(animations.shift());
函数定向(图像){
image.fadeIn(“慢”,函数(){
//等待动画完成,如果有更多动画,则递归
如果(animations.length>0)实现动画(animations.shift());
});
}

你几乎做对了!而不是:

//var el = $(".lazyOwl", this);
您应该使用以下选项:

var el = $(this);

跳跃“延迟”是由动画引起的。如果删除动画,它会立即显示正确的位置:

//  $('html, body').animate({
//    scrollTop: offset
//  }, speed);
  $('html, body').scrollTop(offset);

你几乎是对的!而不是:

//var el = $(".lazyOwl", this);
您应该使用以下选项:

var el = $(this);

跳跃“延迟”是由动画引起的。如果删除动画,它会立即显示正确的位置:

//  $('html, body').animate({
//    scrollTop: offset
//  }, speed);
  $('html, body').scrollTop(offset);

但当你按下编号的按钮时,会有一种“延迟”的情况发生。就像它在最终提交整个过程之前发生了轻微的变化。但是当你按下编号的按钮时,会有一种“延迟”发生。就像它在最终完成整个过程之前发生了轻微的变化。