简体   繁体   English

如何使用jquery将css逐行添加到多个div中

[英]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.

相关问题 jQuery显示一个接一个地隐藏多个div - jquery show hide multiple divs one after another 一个接一个地改变多个div的颜色 - changing color of multiple divs one after another 如何使用JQuery将HTML内容从一页上的div加载到另一页上的多个div? - How do I load HTML content from divs on one page into multiple divs on another page with JQuery? 每次滚动到底部时,jquery fadeIn()多个div接一个 - Jquery fadeIn() multiple divs one after another when scrolled to the bottom each time 如何添加两个不同div的CSS高度,并使用jquery将高度设置为另一个div - How can I add two CSS heights of different divs and make that the height to another div with jquery 如何在鼠标悬停时添加多个div(jQuery) - How to add multiple divs in mouseover (jquery) jQuery UI可排序 - 使用不同的宽度一个接一个地保持div - jQuery UI sortable - keep the divs one after another with different widths 堆叠两个div并一个接一个地滑动以使用jQuery - Stack two divs and slide one after another is removed w/jQuery 如何在jQuery中将多个div的值相加并将最终总和追加到另一个div? - How do I add up the values of multiple divs in jQuery and append the final sum to another div? 单击多个div一个接一个地触发另一个div动画? - clicking on multiple divs one after the other to trigger another div animation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM