Is it possible to set the equivalent of a src attribute of an img tag in CSS?

后端 未结 25 2572
借酒劲吻你
借酒劲吻你 2020-11-22 09:30

Is it possible to set the src attribute value in CSS? At present, what I am doing is:


25条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 10:04

    Loading IMG src from CSS definition, using modern CSS properties

    
    
    
    
    

    • the empty src definition on an triggers the onerror handler: loadIMG function
    • loadIMG function calculates the CSS value
    • strips all illegal characters
    • sets the IMG.src
    • when the CSS changes, the image is NOT updated! You have to call loadIMG again

    JSFiddle: https://jsfiddle.net/CustomElementsExamples/vjfpu3a2/

提交回复
热议问题