这是我的聚合物元素:
<link rel="import" href="../polymer/polymer.html">
<script src="bower_components/cytoscape/dist/cytoscape.js"></script>
<dom-module id="dependency-graph">
<template>
<style>
#surface {
width: 200px;
height: 200px;
}
</style>
<div id="surface"></div>
</template>
<script>
Polymer({
is: 'dependency-graph',
ready: function () {
var surface = this.$.surface;
var cy = cytoscape({
container: surface
});
...
运行它会在 cytoscape 中引发异常
return ( _p.sizeCache = _p.sizeCache || ( container ? (function(){
var rect = container.getBoundingClientRect();
var style = window.getComputedStyle( container );
var val = function( name ){ return parseFloat( style.getPropertyValue( name ) ); };
return {
width: rect.width - val('padding-left') - val('padding-right') - val('border-left-width') - val('border-right-width'),
height: rect.height - val('padding-top') - val('padding-bottom') - val('border-top-width') - val('border-bottom-width')
};
因为style.getPropertyValue
返回""
。如果我document.body
用作容器,它将返回一个数字并且 cytoscape 可以工作。我做错了什么,我该如何解决?
我找到了一篇关于类似问题的文章,但我没有得到它(或者它不起作用?):webcomponentsjs is not compatible with third-party scripts that use window.getComputedStyle