[英]how to add css to multiple divs in a row and one after another with jquery
I am adding css background to multiple divs
and I want to do it in a row and one after another.我正在向多个
divs
添加 css 背景,我想连续一个接一个地进行。 Now that I add css to all divs
, it adds all the background-images
to all divs
at once which makes the images to load slowly.现在我将 css 添加到所有
divs
,它一次将所有background-images
到所有divs
,这使得图像加载缓慢。
this is my jquery code :这是我的 jquery 代码:
$('#m-portfolio .slick-slide').each(function(){
var $item = $(this),
img = $item.find('.m-p-view').attr('data-lazyload'),
bg = $item.find('.m-p-view').attr('data-bg');
$item.find('div.slice').css('background-image', 'url(' + img + ')');
$item.find('.m-p-view').css('background-image', 'url(' + bg + ')');
});
$(function () {
$('#m-portfolio .slick-slide').each(function (i, item) {
var $item = $(this).hide(),
$mpview = $item.find('.m-p-view'),
$slice = $item.find('.slice'),
img = $mpview.attr('data-lazyload'),
bg = $mpview.attr('data-bg');
$('<img src="' + img + '" />').load(function () {
$slice.css('background-image', 'url(' + img + ')');
$('<img src="' + bg + '" />').load(function () {
$mpview.css('background-image', 'url(' + bg + ')').parent('.slick-slide').delay(i + '000').fadeIn();
});
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.