Detect support for background-attachment: fixed?

前端 未结 7 1768
花落未央
花落未央 2020-12-31 02:09

Is there a way to detect browser support for background-attachment: fixed?

Edit: Although this feature is widely supported on desktop browsers it is poorly supported

7条回答
  •  暖寄归人
    2020-12-31 03:05

    Support for any CSS property value can be detected via following steps:

    1. create a temporary element (e.g. DIV);
    2. set value of its style DOM property (element.style.backgroundAttachment in your case) to value to check (fixed in your case);
    3. compare actual style value with specified string.

    Something like this in your case:

    var elem = document.createElement('div');
    elem.style.backgroundAttachment = 'fixed';
    var isSupported = 'fixed' === elem.style.backgroundAttachment;
    

提交回复
热议问题