Javascript 猫头鹰转盘&x2B;URL+;幻灯片项目更改
我想在javascript/jQuery中做3件事Javascript 猫头鹰转盘&x2B;URL+;幻灯片项目更改,javascript,jquery,carousel,owl-carousel,Javascript,Jquery,Carousel,Owl Carousel,我想在javascript/jQuery中做3件事 为每个项目创建URL(我当前正在使用location.hash) 根据提供的URL更改当前项目(我当前正在获取location.hash并访问幻灯片编号) 确保缩略图/幻灯片都根据URL进行相应更改 我遇到了一些问题,我相信我可以解决。然而,我不确定我是否以最合理/有效的方式进行这项工作。以下是我目前的职能: function slideUrl(el) { var current = this.currentItem; var slid
function slideUrl(el) {
var current = this.currentItem;
var slide = location.hash;
if(location.hash === '') {
location.hash = 'slide' + current;
} else {
var goToSlide = slide.replace("#slide","");
sync1.trigger("owl.jumpTo", goToSlide);
el.find(".owl-item").eq(goToSlide).addClass("synced");
sync2.trigger("owl.jumpTo", goToSlide);
this.currentItem = goToSlide;
console.log(this.currentItem);
}
}
我遇到的问题包括:
当前项目没有改变,因此如果我转到提供的URL(比如幻灯片9)并单击“下一步”,幻灯片将转到1对10,因为它认为它位于幻灯片0上
我不确定这是否是一个问题,但我相信如果我将url-/demos/sync.html#slide2更改为/demos/sync.html#slide3,我必须刷新两次
任何关于这方面的帮助/更好的想法都会非常有用 我认为这段代码会对您有所帮助(这不是您代码的完美答案)
我也有同样的问题。如何解决: 1) 打开owl.carousel.js 2) 跳转到以下位置: base.currentItem=base.owl.currentItem=位置 将其设置为: base.currentItem=parseInt(base.owl.currentItem=position,10) 3) 在后藤,同样的事情: 更改base.currentItem=base.owl.currentItem=position 进入 base.currentItem=parseInt(base.owl.currentItem=position,10) 你完成了。看起来是字符串和整数之间的类型不匹配,使得下一张幻灯片的索引不存在,即在幻灯片3生成所需索引31而不是4后滚动一张幻灯片
$("#owl-demo").owlCarousel({
items: 6,
scrollPerPage: true,
itemsDesktop: [1199,5],
itemsDesktopSmall: [979,4],
itemsTablet: [768,4],
itemsTabletSmall: [479,3],
itemsMobile: [360,2]
});
owl = $("#owl-demo").data('owlCarousel');
$('.go').on('click', function(){
var inputVal = parseInt($('input').val()) - 1;
owl.jumpTo(inputVal);
});