make image( not background img) in div repeat?

前端 未结 4 786
我寻月下人不归
我寻月下人不归 2021-02-19 02:03

I\'m trying to repeat-y an image that\'s in a div and no background image but haven\'t figured how. Could you please point me to a solution?

My code looks like this:

4条回答
  •  遥遥无期
    2021-02-19 02:45

    Not with CSS you can't. You need to use JS. A quick example copying the img to the background:

    var $el = document.getElementById( 'rightflower' )
      , $img = $el.getElementsByTagName( 'img' )[0]
      , src  = $img.src
    
    $el.innerHTML = "";
    $el.style.background = "url( " + src + " ) repeat-y;"
    

    Or you can actually repeat the image, but how many times?

    var $el = document.getElementById( 'rightflower' )
      , str = ""
      , imgHTML = $el.innerHTML
      , i, i2;
    for( i=0,i2=10; i

提交回复
热议问题