[英]Click event on owl-item not triggered in owl carousel 1.3.3 when navigation is true
Anyone help me on owl-carousel.任何人帮助我猫头鹰旋转木马。 Click event on item not triggered in owl carousel v1.3.3 while navigation is on.
导航打开时,在 owl carousel v1.3.3 中不会触发项目上的单击事件。 My code is:
我的代码是:
$(document).ready(function () {
$('.owl-carousel').owlCarousel({
items: 3,
mouseDraggable: false,
navigation: true,
scrollPerPage: true,
rewindNav: false,
pagination: false,
navigationText: ['<span><</span>', '<span>></span>'],
})
$('.owl-carousel').on('click', '.owl-item>div', function () {
alert('click');
})
})
$(document).ready(function() { var owl = $('.owl-carousel'); owl.owlCarousel({ margin: 10, navigation: true, loop: true, }) $('.owl-carousel').on('click', '.owl-item>div', function () { alert('click'); }) })
.owl-carousel.item { height: 10rem; background: #4DC7A0; padding: 1rem; margin: 1rem; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css" rel="stylesheet" /> <link href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script> <div class="owl-carousel owl-theme"> <div class="item"> <h4>1</h4> </div> <div class="item"> <h4>2</h4> </div> <div class="item"> <h4>3</h4> </div> <div class="item"> <h4>4</h4> </div> <div class="item"> <h4>5</h4> </div> <div class="item"> <h4>6</h4> </div> <div class="item"> <h4>7</h4> </div> <div class="item"> <h4>8</h4> </div> <div class="item"> <h4>9</h4> </div> <div class="item"> <h4>10</h4> </div> <div class="item"> <h4>11</h4> </div> <div class="item"> <h4>12</h4> </div> </div>
There is a good chance that owl carousel stops the propagation of events from the parent element ( '.owl-carousel'
).owl carousel 很有可能会停止从父元素 ( '.owl-carousel'
) 传播事件。
So rather than adding the click event on '.owl-carousel'
and reaching its child, add it on the child '.owl-item>div'
directly.因此,与其在'.owl-carousel'
上添加点击事件并到达其子项,不如将其直接添加到子'.owl-item>div'
上。
Update: Try this, make sure to set your event listener after the document is loaded.更新:试试这个,确保在加载文档后设置事件侦听器。 This gives a good enough time for your HTML to render.
这为您的 HTML 提供了足够的时间来渲染。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.