A better implementation of a fading image swap with javascript / jQuery

前端 未结 3 1886
一个人的身影
一个人的身影 2021-01-20 07:26

This is less of a specific problem or error but more of a implementation question.

First of I\'d like to say that I\'ve been through a lot of fading image tutorials

3条回答
  •  情歌与酒
    2021-01-20 07:55

    Here's a nice pattern:

    
    

    JS:

    $('body').find('*[hoverImg]').each(function(index){
        $this = $(this)
        $this.wrap('
    ') $this.parent().css('width',$this.width()) $this.parent().css('height',$this.width()) $this.parent().css('background-image',"url(" + $this.attr('hoverImg')+")") $this.hover(function() { $(this).stop() $(this).fadeTo('',.01) },function() { $(this).stop() $(this).fadeTo('',1) }) });

提交回复
热议问题