Dojo学习笔记(十五):Dojo滑动条Slider

    Slider没有相对应的 HTML 控件,是一个相对独立的图形化的组件,可以通过鼠标、方向键来控制刻度尺的刻度。Dijit提供了水平和垂直滑动条。

    Slider widget的使用却如同使用 CheckBox widget一样的方便。用户可以用鼠标点击、拖拉、中键滚动或者用键盘的上、下、左、右按键来选择Slider widget的刻度。

    Silder 是由六个 widgets 组成,分别是:dijit.form.HorizontalSlider, dijit.form.VerticalSlider,dijit.form.HorizontalRule, dijit.form.VerticalRule,dijit.form.HorizontalRuleLabels, dijit.form.VerticalRuleLabels。        

    dijit.form.HorizontalSlider是水平方向的slider, dijit.form.VerticalSlider 是垂直方向的slider,提供可调节大小的标尺。其属性如下:

滑动条:HorizontalSlider 和 VerticalSlider 的属性

属性 属性类别 描述
clickSelect boolean
true
指定单击进度条是否可以更改刻度值
discreteValues integer
Infinity
在最大值与最小值之间可以设置的非连续值得个数
intermediateChanges Boolean
false
判断在调用 setValue 方法时是否直接触发 onChange 事件。如果为’ true ’,则每次执行 setValue 方法时都会触发 onChange 事件;如果为’ false ’,则 onChange 事件只有在自己被调用时才会被触发。
maximum integer
100
可设置的最大刻度值
minimum integer
0
可设置的最小刻度值
pageIncrement integer
2
点击键盘按键 pageup/pagedown 时一次变化的刻度值
showButtons boolean
true
指定是否在刻度条两端显示增加和减小的按钮

    函数increment()表示以1单位为步长增加滑动条的值;函数decrement()表示以1单位为步长减少滑动条的值。

刻度尺:HorizontalRule 和 VerticalRule 的属性

属性 属性类别 描述
container Node
containerNode
设置刻度尺或文本标签相对于滑动条的位置,HorizontalSlider使用topDecoration或bottomDecoration,VerticalSlider使用leftDecoration或rightDecoration。
count Integer
3
指定生成刻度线的数量
ruleStyle String 指定刻度线设置 CSS style

    dijit.form.HorizontalRuleLabels, dijit.form.VerticalRuleLabels 可以为标尺提供刻度标签,其属性如下:

标签:HorizontalRuleLabels 和 VerticalRuleLabels 的属性

属性 属性类别 描述
labels Array
[]
文本标签的数组,存放要展现的标签值
labelStyle String 指定为文本标签设置 CSS style
minimum

Integer

0

在没有指定标签数组情况下,以这个值最左(下)端标签
maximum

Integer

1

在没有指定标签数组情况下,以这个值最右(上)端标签
getLabels

Function

[]

返回labels数组
constraints

Object

{pattern:"#%"}

在没有指定标签数组情况下,使用这个对象包含的模式来生成数字标签


--声明方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"en" >
     "utf-8" >
     Demo: Slider
     "stylesheet"  href= "dijit/themes/claro/claro.css" >
     "dojo/dojo.js"  data-dojo-config= "async: true, parseOnLoad: true" >
    
class = "claro" >
"vertSlider"     data-dojo-type= "dijit/form/VerticalSlider"
        data-dojo-props= "minimum: 0,maximum: 100,pageIncrement: 20,value: 20,intermediateChanges: true,style: 'height: 200px;'" >

--编程方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"en" >
     "utf-8" >
     Demo: Slider
     "stylesheet"  href= "dijit/themes/claro/claro.css" >
     "dojo/dojo.js"  data-dojo-config= "async: true, parseOnLoad: true" >
    
class = "claro" >
"vertSlider"  />

输出:

wKioL1RYmW_TYP-fAAANP0LKVfM164.jpg


--添加文本标签,创建水平滑动条:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"en" >
     "utf-8" >
     Demo: Slider
     "stylesheet"  href= "dijit/themes/claro/claro.css" >
     "dojo/dojo.js"  data-dojo-config= "async: true, parseOnLoad: true" >
    
class = "claro" >
"width: 600px;margin-left: 30px;" >
    
     "dijit/form/HorizontalRuleLabels"
         data-dojo-props= "container: 'topDecoration',count: 11,numericMargin: 0"
         style= "height: 1.2em; font-weight: bold" >
    
    
     "dijit/form/HorizontalRule"
          data-dojo-props= "container: 'topDecoration',count: 11"
          style= "height: 5px;margin:0  12px;" >
    
    
     "hslider"  type= "range"  value= "3"
            data-dojo-type= "dijit/form/HorizontalSlider"
            data-dojo-props= "minimum: 0,maximum: 10,showButtons: false,discreteValues: 11" >
    
     "dijit/form/HorizontalRule"
          data-dojo-props= "container: 'bottomDecoration',count: 5"
          style= "height: 5px; margin: 0 12px;" >
    
    
     "dijit/form/HorizontalRuleLabels"
         data-dojo-props= "container: 'bottomDecoration'"
         style= "height: 1em; font-weight: bold;" >
        
  • lowest
  •         
  •         
  • lowest2
  •         
  • normal
  •         
  • highest
  •     

    输出:

    wKiom1RYq2WgF4IfAABVGxgWhlk780.jpg


    --添加文本标签,创建垂直滑动条:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    "en" >
         "utf-8" >
         Demo: Slider
         "stylesheet"  href= "dijit/themes/claro/claro.css" >
         "dojo/dojo.js"  data-dojo-config= "async: true, parseOnLoad: true" >    
    class = "claro" >
    "vertSlider" >

    输出:

    wKiom1RYsG6hvY-xAAAWd2-dVIw434.jpg


    --创建水平刻度:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    "en" >
         "utf-8" >
         Demo: Slider
         "stylesheet"  href= "dijit/themes/claro/claro.css" >
         "dojo/dojo.js"  data-dojo-config= "async: true, parseOnLoad: true" >
        
    class = "claro" >
    "dijit.form.HorizontalSlider"  name= "caffeine"
          value= "100"
          maximum= "175"
          minimum= "2"
          showButtons= "false"
          style= "margin: 5px;width:300px; height: 20px;" >
         "dojo/method"  event= "onChange"  args= "newValue" >
             console.log(newValue);
        
         "dijit.form.HorizontalRuleLabels"  container= "topDecoration"
             style= "height:10px;font-size:75%;color:gray;"  count= "6" >
        
         "dijit.form.HorizontalRule"  container= "topDecoration"
              count= 6  style= "height:5px;" >
        
         "dijit.form.HorizontalRule"  container= "bottomDecoration"
              count= 5  style= "height:5px;" >
        
         "dijit.form.HorizontalRuleLabels"  container= "bottomDecoration"
             style= "height:10px;font-size:75%;color:gray;" >
            
  • green
    tea
  •         
  • coffee
  •         
  • red
    bull
  •     

    输出:

    wKioL1RYsoiBB6KgAAAkmq__a0c486.jpg

    --创建垂直刻度

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    "en" >
         "utf-8" >
         Demo: Slider
         "stylesheet"  href= "dijit/themes/claro/claro.css" >
         "dojo/dojo.js"  data-dojo-config= "async: true, parseOnLoad: true" >
        
    class = "claro" >
    "dijit.form.VerticalSlider"  name= "caffeine"
          value= "100"
          maximum= "175"
          minimum= "2"
          showButtons= "false"
          style= "margin: 5px;width:75px; height: 300px;" >
         "dojo/method"  event= "onChange"  args= "newValue" >
             console.log(newValue);
        
         "dijit.form.VerticalRuleLabels"  container= "leftDecoration"
             style= "height:300px;width:25px;font-size:75%;color:gray;"  count= "6" >
        
         "dijit.form.VerticalRule"  container= "leftDecoration"
              count= 6  style= "height:300px;width:5px;" >
        
         "dijit.form.VerticalRule"  container= "rightDecoration"
              count= 5  style= "height:300px;width:5px;" >
        
         "dijit.form.VerticalRuleLabels"  container= "rightDecoration"
             style= "height:300px;width:25px;font-size:75%;color:gray;" >
            
  • green tea
  •         
  • coffee
  •         
  • red bull
  •     

    输出:

    Dojo学习笔记(十五):Dojo滑动条Slider_第1张图片


        总结:分为三步(1)创建滑动条(2)创建刻度尺(3)创建标签。






    参考:

    http://dojotoolkit.org/documentation/tutorials/1.10/sliders/

    http://www.ibm.com/developerworks/cn/web/wa-lo-dojointro5/

    http://www.ibm.com/developerworks/cn/views/web/libraryview.jsp?search_by=掌握+Dojo






         本文转自stock0991 51CTO博客,原文链接:http://blog.51cto.com/qing0991/1571645,如需转载请自行联系原作者








    你可能感兴趣的:(Dojo学习笔记(十五):Dojo滑动条Slider)