假设我有以下代码:
var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-8.75, 2.5, 8.75, -2.5]});
var ax2 = brd2.create('axis', [[0,0],[1,0]]);
如何更改轴的第二点?
像ax2.setSecondPoint([2,0])之类的东西?
通常,如何设置任何元素的属性?
谢谢。
最佳答案
Axis有两个属性,其名称不言自明:point1和point2。
您可以在其中任何一个上使用setPosition方法,例如
ax2.point2.setPosition(JXG.COORDS_BY_USER,[2,0])
现在有一个问题:除非将轴对象的
needsRegularUpdate
属性设置为true
,否则您不会在图表上看到此更改。最后,要刷新图表,您应该在board变量上执行fullUpdate()
方法。整体看起来像这样:var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-8.75, 2.5, 8.75, -2.5]});
var ax2 = brd2.create('axis', [[0,0],[1,0]],{needsRegularUpdate:true});
ax2.point2.setPosition(JXG.COORDS_BY_USER,[2,0]);
brd2.fullUpdate();
参考文献:
http://jsxgraph.uni-bayreuth.de/docs/symbols/JXG.Point.html#setPosition
http://jsxgraph.uni-bayreuth.de/wiki/index.php/Options(搜索“特殊轴选项”)
现在要更改
fixed
,visible
等属性,您应该使用setAttribute
方法(不建议使用setProperty
)。例:// Set property directly on creation of an element using the attributes object parameter
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-1, 5, 5, 1]};
var p = board.create('point', [2, 2], {visible: false});
// Now make this point visible and fixed:
p.setAttribute({
fixed: true,
visible: true
});
资源:
http://jsxgraph.uni-bayreuth.de/docs/symbols/JXG.GeometryElement.html#setAttribute
最后但并非最不重要的一个简单公式:
a + b = c
哪里:
a =在浏览器中使用JavaScript调试工具来调查对象属性
b =检查所用产品的文档
c =成功:)