Trigger event on background image load

后端 未结 4 1456
甜味超标
甜味超标 2021-01-11 11:56

Is there a way, using jQuery, to trigger an event on load of a CSS background image?

4条回答
  •  借酒劲吻你
    2021-01-11 12:16

    $(document).ready(function(){
    $('img, .hasBGI').css('opacity',0)
    
    $('.hasBGI').each(function(){
        var $this = $(this)
            $bgi = $('')
            // $bgi.css(/*hiddingStyle*/)
            $('body').append($bgi)
            $bgi.load(function(){
                $(this).remove()
                $this.animate({opacity:1})
            })
    })
    $('img').load(function(){
        $(this).animate({opacity:1})
    })
    

    })

提交回复
热议问题