admin管理员组文章数量:1414902
I am using owl-carousel which is working pretty good when I load items directly. Although, when I try to load items through AJAX, those been rendered but not been displayed properly and not even navigation works.
JQuery to initialize carousel
$(".pos-carousel").owlCarousel({
center: true,
items: 1,
loop: true,
margin: 15,
nav: true,
responsive: {
640: {
items: 2,
autoWidth: true,
margin: 30
}
}
});
HTML....
<div id="creationSelectItem">
<div class="module-content carousel owl-carousel owl-theme pos-carousel creationSelectItem-carousel">
</div>
JQuery that loads the items
$(".brand-selection-item img").click(function () {
var selectedBrand = $(this).attr('data-selected-Brand');
$.get("/umbraco/surface/POSCreate/GetTypeStyleOptions", { brandName: selectedBrand }, function (data) {
$(".creationSelectItem-carousel").html(data);
});
});
I get this log on console: error log Any help is wele!
I am using owl-carousel which is working pretty good when I load items directly. Although, when I try to load items through AJAX, those been rendered but not been displayed properly and not even navigation works.
JQuery to initialize carousel
$(".pos-carousel").owlCarousel({
center: true,
items: 1,
loop: true,
margin: 15,
nav: true,
responsive: {
640: {
items: 2,
autoWidth: true,
margin: 30
}
}
});
HTML....
<div id="creationSelectItem">
<div class="module-content carousel owl-carousel owl-theme pos-carousel creationSelectItem-carousel">
</div>
JQuery that loads the items
$(".brand-selection-item img").click(function () {
var selectedBrand = $(this).attr('data-selected-Brand');
$.get("/umbraco/surface/POSCreate/GetTypeStyleOptions", { brandName: selectedBrand }, function (data) {
$(".creationSelectItem-carousel").html(data);
});
});
I get this log on console: error log Any help is wele!
Share Improve this question edited Sep 12, 2017 at 8:34 asked Sep 12, 2017 at 8:07 user8596307user85963073 Answers
Reset to default 4you need to initialize the carousel after loading the data :
$.get("/umbraco/surface/POSCreate/GetTypeStyleOptions", { brandName: selectedBrand }, function (data) {
$(".creationSelectItem-carousel").html(data);
$(".pos-carousel").owlCarousel({
center: true,
items: 1,
loop: true,
margin: 15,
nav: true,
responsive: {
640: {
items: 2,
autoWidth: true,
margin: 30
}
}
});
});
Add carousel js inside success function..
jQuery.ajax({
type: "POST",
url: "file.php",
cache: false,
beforeSend: function() {
//add loader before send
},
success: function(html) {
//owl carosel slider js here
jQuery(".creationSelectItem-carousel").html(html);
jQuery(".pos-carousel").owlCarousel({
center: true,
items: 1,
loop: true,
margin: 15,
nav: true,
responsive: {
640: {
items: 2,
autoWidth: true,
margin: 30
}
}
});
}
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.0/jquery.min.js"></script>
Try this, after lots of tries I can solve it.
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
dataType: 'html',
data: {
category: catName,
},
success: function(response) {
$('.show_best_top_popular').html(response);
var owl = $('.owl-carousal');
owl.trigger('destroy.owl.carousel');
owl.owlCarousel({
loop: true,
margin: 10,
nav: true,
});
}
});
本文标签: javascriptowl carousel doesn39t work properly on ajax loaded itemsStack Overflow
版权声明:本文标题:javascript - owl carousel doesn't work properly on ajax loaded items - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745188542a2646799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论