1
即时通讯使用swiper插件,但似乎无法获得任何方法的工作。Swiper - 方法将无法工作 - mySwiper.slideTo不是一个函数
我jQuery和刷卡加入这样的:
<script src="jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="swiper.jquery.js" type="text/javascript">
在我的HTML的底部。 我刷卡初始化像这样的文件准备:
mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
pagination: '.swiper-pagination',
paginationType: 'fraction',
grabCursor: true,
keyboardControl: true,
onSlideChangeStart: function(){
$('video').each(function() {
$(this)[0].pause();
});
$(".swiper-slide-active video").each(function() {
$(this)[0].play();
});
if ($(".swiper-slide-active").hasClass("layout4"))
{
video_visible = 1;
$(".section").css("background-color", "black");
$("body").css("color", "white");
$(".swiper-button-prev").css("background-image", "url(img/leftArrowW.png)");
$(".swiper-button-next").css("background-image", "url(img/rightArrowW.png)");
$(".swiper-button-prev").css("opacity", "0.25");
$(".swiper-button-next").css("opacity", "0.25");
$(".headline").css("opacity", "0.25");
$(".swiper-pagination").css("opacity", "0.25");
}
else {
video_visible = 0;
$(".section").css("background-color", "white");
$("body").css("color", "black");
$(".section .swiper-button-prev").css("background-image", "url(img/leftArrow.png)");
$(".section .swiper-button-next").css("background-image", "url(img/rightArrow.png)");
$(".swiper-button-prev").css("opacity", "1");
$(".swiper-button-next").css("opacity", "1");
$(".headline").css("opacity", "1");
$(".swiper-pagination").css("opacity", "1");
}
if ($(".swiper-slide-active").hasClass("layout7"))
{
$(".layout7").css("background-color", "#e0e8eb");
}
},
loop: true ,
});
,我想调用的函数是:
$('.section .down').waypoint(function(direction){
if ($(".swiper-slide-active").hasClass("layout4")){
if (direction == 'down') {
if (!once_d){
mySwiper.slideTo(1,100,false);
$(".section").css("background-color", "white");
$("body").css("color", "black");
$(".swiper-button-prev").css("background-image", "url(img/leftArrow.png)");
$(".swiper-button-next").css("background-image", "url(img/rightArrow.png)");
$(".swiper-button-prev").css("opacity", "1");
$(".swiper-button-next").css("opacity", "1");
$(".headline").css("opacity", "1");
$(".swiper-pagination").css("opacity", "1");
$('video').each(function() {
$(this)[0].pause();
});
video_visible = 0;
once_d = true;
}
else{
return;
}
}
}
}, { offset: "-25%" });
我得到的错误是:
Uncaught TypeError: mySwiper.slideTo is not a function
at Waypoint.$.waypoint.offset [as callback]
出现这种情况,不管我尝试执行什么方法。 我试过
mySwiper.update();
也是。
我怀疑错误可能来自我的swiper/jQuery文件,但我也尝试redownloading。如果后
在此先感谢
您的航点是否也在document.ready中初始化以避免它在swiper变量创建之前执行?如果您在航点呼叫中执行了'console.log(mySwiper)',那么您是否在控制台中获得任何东西,或者mySwiper在该点处未定义? – delinear
我在我的方法调用之前添加了console.log(mySwiper),并得到: (2)[Swiper,Swiper] –
因此,这可能意味着您正在获取一组滑动对象,[Swipe,Swipe] ... (012)(0).pause(); });( $('video')。each(function(){ $(this)[0] .pause(); });如果你要做的唯一事情是[0]索引,你不需要做每条语句,你可以做$('video')[0] .pause()或$('video')。 (0).pause();因为小事情可能会导致脚本在将来的代码中出现错误。 – Ezekiel