回調
而不是附加的事件處理程序,你也可以只添加一個回調貓頭鷹旋轉木馬的選項。
$('.owl-carousel').owlCarousel({
onDragged: callback
});
function callback(event) {
...
}
數據
每個事件傳遞事件對象內非常有用的信息。根據上面的例子:
function callback(event) {
// Provided by the core
var element = event.target; // DOM element, in this example .owl-carousel
var name = event.type; // Name of the event, in this example dragged
var namespace = event.namespace; // Namespace of the event, in this example owl.carousel
var items = event.item.count; // Number of items
var item = event.item.index; // Position of the current item
// Provided by the navigation plugin
var pages = event.page.count; // Number of pages
var page = event.page.index; // Position of the current page
var size = event.page.size; // Number of items per page
}
來源:
http://www.owlcarousel.owlgraphic.com/docs/api-events.html
你的例子看起來好像沒什麼問題,之後和之前只是打印,以確保您的財產將被owlCarroussel採取。你添加了正確的jQuery頭?
<a href="http://jquery.com/">jQuery</a>
<script src="jquery.js"></script>
<script>
var owl = $('.owl-carousel');
alert('before')
owl.owlCarousel({
onDragged: callback,
animateOut: 'fadeOut',
animateIn: 'fadeIn',
items: 1,
loop: true,
autoplay: false,
nav: true,
dots: true
});
alert('After')
function callback(event) {
var pages = event.page.count; // Number of pages
console.log(pages);
}
</script>
您是否在腳本中添加了jquery?看起來對我來說很好...只需在owl.owlCarousel之前打印以確保在拖動之前設置屬性。 – Destrif