以下是来自Owl Carousel的own site的代码。我不知道为什么不调用回调函数(此处为afterMove)!有人可以调用afterMove函数吗?对我来说,这不仅是afterMove,而且所有回调都不起作用!
<html>
<head>
<!-- Owl Carousel -->
<link rel="stylesheet" href="js/vendors/owl-carousel-2/assets/owl.carousel.min.css">
<!-- Owl Default Theme -->
<link rel="stylesheet" href="js/vendors/owl-carousel-2/assets/owl.theme.default.min.css">
<style type="text/css">
#owl-demo .item {
background: #3fbf79;
padding: 30px 0px;
margin: 10px;
color: #FFF;
border-radius: 3px;
text-align: center;
}
</style>
</head>
<body>
<div id="owl-demo" class="owl-carousel">
<div class="item"><h1>0</h1></div>
<div class="item"><h1>1</h1></div>
<div class="item"><h1>2</h1></div>
<div class="item"><h1>3</h1></div>
<div class="item"><h1>4</h1></div>
<div class="item"><h1>5</h1></div>
<div class="item"><h1>6</h1></div>
</div>
<!-- jQuery -->
<script src="js/jquery/1.9.1/jquery.min.js"></script>
<!-- Owl Carousel -->
<script src="js/vendors/owl-carousel-2/owl.carousel.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var owl = $("#owl-demo");
owl.owlCarousel({
navigation : true,
afterMove : afterMove
});
function afterMove(){
alert("Hey!");
}
});
</script>
</body>
</html>
最佳答案
您需要按照其docs中所述,将新事件与.on()
一起使用:
var owl = $("#owl-demo");
owl.owlCarousel({
navigation : true
});
//register `change` event
owl.on('changed.owl.carousel', function(e) {
alert("changed");
});
演示:: jsFiddle
关于javascript - 不调用回调函数(如afterMove),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29295079/