Ajax + JSON.

Descripton

If you call Owl without having content then owl will be in 'stand by' mode and then you can use asynchronous ajax call to fill it with new items. To do this you need to trigger 'insertContent.owl' event with content as a second parameter.

In this example demo.json is a collection of DOM elements. As you can see im passing it as a plain non-jquery string. However 'insertContent.owl' event accept as a second parameter jQuery elements as well, simply use square brackets around jQuery object - owl.trigger('insertContent.owl',[$(content)]);

Note that 'insertContent.owl' replace existence owl items.


//Javascript

var owl = $('.owl-carousel');

owl.owlCarousel({
	nav:true,
	margin:10,
	loop:true,
	responsive:{
		0:{
			items:2
		},
		1000:{
			items:3
		}
	}
});

$.ajax({
	url: '../demos/JSON/demo.json',
	dataType: 'json',
	success: function(data) {
		var content = '';
		for (i in data.owl) {
            content += data.owl[i].item;
        }

		owl.trigger('insertContent.owl',content);
	}
});

	
下载代码说明
X关闭

适应pc客户端、ipad、手机等多种终端浏览器的图

多种版本的,适合目前主流中端的jquery图片滚动插件,适合中端包括 pc客户端、pad客户端以及手机客户端三种。