Cannot covert to JSON value the result of Element.getBoundingClientRect()

后端 未结 1 1631
醉梦人生
醉梦人生 2021-01-21 04:44

I need to convert to a JSON value the result of a DOMRect object returned by Element.getBoundingClientRect()

Here an example:

http://jsfiddle.net/5v

相关标签:
1条回答
  • 2021-01-21 04:52

    Bounding rect only contains "virtual" properties. If you

    console.log(Object.getOwnPropertyNames(r));
    // or
    console.log(Object.keys(r));
    

    you'll get an empty list. JSON.stringify() depends on Object.keys(r) (see comments below) and thus returns an empty object literal.

    Your loop-based approach seems to be a feasible solution to this problem.

    0 讨论(0)
提交回复
热议问题