Home > Web Front-end > JS Tutorial > body text

What should I do if dynamic loading of data always fails when sliding?

php中世界最好的语言
Release: 2018-03-17 13:34:52
Original
2005 people have browsed it

This time I will bring you what to do if the sliding of dynamically loaded data always fails. What should I do to solve the problem of dynamically loaded data sliding always failing?

Two solutions

1. Initialize swiper after loading the data

success:function(result){
var resultdata =eval("("+result+")");
if(resultdata.status == 1){
	var dataList = resultdata.data;
	currentPage = resultdata.currentPage;
	pageCount = resultdata.pageCount;
	var html = "";
	if(pageCount == 0){
		html ='<p class="noCollect">' + resultdata.msg + '</p>';
	}else{
		for(var i in dataList){
			var data = dataList[i];
			html += '<p class="swiper-container artistp">'
			+ '<p class="swiper-wrapper">'
			+ '<p class="swiper-slide workp">'
			+ '<p class="app_inlineBlock workPic">'
			+ '<img class="picImg" src="&#39;+ data.artistAvatar +&#39;" />'
			+ '</p>'+'<p class="app_inlineBlock workInfo">'
			+ '<p class="artistName">' + data.artistName + '</p>'
			+ '<p class="workName">' + data.artworkName + '</p>'
			+ '<p class="workValue">'+ data.typeName +'/'+ data.width + '*' + data.height +'/' +data.createYear + '</p>'
			+ '</p><p class="app_inlineBlockRight workPrice">'
			+ '<p class="price">¥'+ data.marketPrice +'</p></p></p>'
			+ '<p class="swiper-slide delBtn">删除</p></p></p>';
		}
		
	}
	$("#list").append(html);
	//swiper初始化 
	var swiper = new Swiper('.swiper-container', {
		pagination: '.swiper-pagination',
		slidesPerView: 'auto',
		paginationClickable: true,
		spaceBetween: 0
	});
}
Copy after login

2. Add two lines of code to swiper initialization

swiper1 = new Swiper('.swiper-container', { 
 initialSlide :0, 
 observer:true,//修改swiper自己或子元素时,自动初始化swiper 
 observeParents:true//修改swiper的父元素时,自动初始化swiper 
});
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to change the status of radio using JS


##var foo = function () {} and function The difference between foo()


How to set bootstrap table to height percentage

The above is the detailed content of What should I do if dynamic loading of data always fails when sliding?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template