Difference between revisions of "Slider"

From JSXGraph Wiki
Jump to: navigation, search
Line 6: Line 6:
 
<html>
 
<html>
 
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
 
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
 
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
<div id="jxgbox" class="jxgbox" style="width:600px; height:400px;"></div>
 
<div id="jxgbox" class="jxgbox" style="width:600px; height:400px;"></div>
 
<script type="text/javascript">
 
<script type="text/javascript">
 
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 60, unitY: 40, axis:true});         
 
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 60, unitY: 40, axis:true});         
var s = b.createElement('slider',[[0,-3],[4,-3],[1,1,5]]);
+
var s = b.create('slider',[[0,-3],[4,-3],[1,1,5]]);
var s2 = b.createElement('slider',[[1,-3.5],[5,-3.5],[0,1,5]],{name:'s2',snapWidth:1});
+
var s2 = b.create('slider',[[1,-3.5],[5,-3.5],[0,1,5]],{name:'s2',snapWidth:1});
var a = b.createElement('point',[
+
var a = b.create('point',[
                      function(){return s.Value();},
+
                function(){return s.Value();},
                      function(){return 3/s.Value();}
+
                function(){return 3/s.Value();}
                      ],{trace:true});
+
                ],{trace:true});
 
</script>
 
</script>
 
</html>
 
</html>
Line 32: Line 31:
 
<source lang="html4strict">
 
<source lang="html4strict">
 
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
 
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
 
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
<div id="jxgbox" class="jxgbox" style="width:600px; height:400px;"></div>
 
<div id="jxgbox" class="jxgbox" style="width:600px; height:400px;"></div>
Line 38: Line 36:
 
<source lang="javascript">
 
<source lang="javascript">
 
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 60, unitY: 40, axis:true});         
 
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 60, unitY: 40, axis:true});         
var s = b.createElement('slider',[[0,-3],[4,-3],[1,1,5]]);
+
var s = b.create('slider',[[0,-3],[4,-3],[1,1,5]]);
var s2 = b.createElement('slider',[[1,-3.5],[4,-3.5],[0,1,5]],{name:'s2',snapWidth:1});
+
var s2 = b.create('slider',[[1,-3.5],[5,-3.5],[0,1,5]],{name:'s2',snapWidth:1});
var a = b.createElement('point',[
+
var a = b.create('point',[
                      function(){return s.Value();},
+
                function(){return s.Value();},
                      function(){return 3/s.Value();}
+
                function(){return 3/s.Value();}
                      ]);
+
                ],{trace:true});
 
</source>
 
</source>

Revision as of 12:47, 17 February 2010

Sliders enable a convenient way to experiment with mathematical constructions. In the example below there is a slider s which takes values between 1 and 5. The value of the slider can be accessed via s.Value(). The x-coordinate and the y-coordinate of the point A depend on this value s.Value():

The slider needs the following input parameters:

  • [[x1,y1],[x2,y2],[min,start,max]]
  • [x1,y1]: first point of the ruler
  • [x2,y2]: last point of the ruler
  • min: minimum value of the slider
  • start: initial value of the slider
  • max: maximum value of the slider

Properties:

  • snapWidth: distance between two values. (snapWidth:1: slider with integer values)

JavaScript code:

<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id="jxgbox" class="jxgbox" style="width:600px; height:400px;"></div>
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 200, unitX: 60, unitY: 40, axis:true});        
var s = b.create('slider',[[0,-3],[4,-3],[1,1,5]]);
var s2 = b.create('slider',[[1,-3.5],[5,-3.5],[0,1,5]],{name:'s2',snapWidth:1});
var a = b.create('point',[
                 function(){return s.Value();},
                 function(){return 3/s.Value();}
                 ],{trace:true});