http://vote539-webdev.blogspot.com/2011/08/css3-transitions-and-javascript-powered.html
去文字修改版
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" lang= "zh-TW" xml:lang= "zh-TW" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title>Progress Bar</title> <style> .progressbar { position: relative; border: 1px solid #fff; background-color: #ffcccc; /* Original WebKit Syntax for Gradients */ background-image: -webkit-gradient(linear, left top, left bottom, from( #ffcccc), color-stop(50%, #fff), to( #ffcccc)); /* More Recent Syntax for Gradients */ background-image: -webkit-linear-gradient( top, #ffcccc 0%, #fff 50%, #ffcccc 100%); background-image: -moz-linear-gradient( top, #ffcccc 0%, #fff 50%, #ffcccc 100%); background-image: -o-linear-gradient( top, #ffcccc 0%, #fff 50%, #ffcccc 100%); background-image: -ms-linear-gradient( top, #ffcccc 0%, #fff 50%, #ffcccc 100%); } .pb-fluid { position: absolute; top: 0px; left: 0px; height: inherit; /* Here is where we declare the CSS3 Transitions. * We have one line for each browser prefix, plus * the future standard at the end. */ -webkit-transition: width .6s ease; /* WebKit (3.2+) Version */ -moz-transition: width .6s ease; /* Firefox (4+) Version */ -o-transition: width .6s ease; /* Opera (10.5+) Version */ -ms-transition: width .6s ease; /* Internet Explorer (10+?) Version */ transition: width .6s ease; /* Future Standard */ background-color: #ff0000; background-image: -webkit-gradient(linear, left top, left bottom, from( #ffcccc), color-stop(50%, #ff0000), to( #ffcccc)); background-image: -webkit-linear-gradient( top, #ffcccc 0%, #ff0000 50%, #ffcccc 100%); background-image: -moz-linear-gradient( top, #ffcccc 0%, #ff0000 50%, #ffcccc 100%); background-image: -o-linear-gradient( top, #ffcccc 0%, #ff0000 50%, #ffcccc 100%); background-image: -ms-linear-gradient( top, #ffcccc 0%, #ff0000 50%, #ffcccc 100%); } </style> </head> <body> <div id= "container" style= "position:relative;" ></div> <script type= "text/javascript" > function ProgressBar() { var width = 500; var height = 3; var objects = {}; var max = 1; var value = 0; var _redraw = function () { if (objects.main) { objects.fluid.innerHTML = "" ; objects.text.innerHTML = "" ; objects.main.innerHTML = "" ; objects.main.parentNode.removeChild(objects.main); } objects.main = document.createElement( "div" ); objects.main.className = "progressbar" ; objects.main.style.width = width + "px" ; objects.main.style.height = height + "px" ; objects.fluid = document.createElement( "div" ); objects.fluid.className = "pb-fluid" ; objects.main.appendChild(objects.fluid); } var _setfluid = function (){ if (!objects.main) _redraw(); var percentage; if (max<=0) { percentage=0; } else if (value<0) { percentage=0; } else if (value>=max) { percentage=1; } else { percentage=value/max; } objects.fluid.style.width = Math.round(percentage*width) + "px" ; } this .appendTo = function (target) { if (!objects.main) { _redraw(); } target.appendChild(objects.main); } this .jump = function () { if (!objects.main) return ; if (objects.main.parentNode) { var parent=objects.main.parentNode; } _redraw(); _setfluid(); if (parent) { parent.appendChild(objects.main); } } this .setWidthHeight = function (newwidth, newheight) { if (newwidth) { width = newwidth; } if (newheight) { height = newheight; } _redraw(); _setfluid(); } this .setValueMax = function (newvalue, newmax) { value = newvalue; max = newmax; _setfluid(); } this .setValue = function (newvalue) { value = newvalue; _setfluid(); } this .setMax = function (newmax) { max = newmax; _setfluid(); } this .getValue = function () { return value; } this .getMax = function () { return max; } } var myProgressBar = new ProgressBar(); //myProgressBar.setWidthHeight(200, 18); myProgressBar.setValueMax(0, 10); myProgressBar.setValue(5); myProgressBar.appendTo(document.getElementById( "container" )); </script> <p> <button onclick= "myProgressBar.setValue(myProgressBar.getValue()+1);" >Increase Value</button> <button onclick= "myProgressBar.setValue(myProgressBar.getValue()-1);" >Decrease Value</button> </p> </body> </html> |
沒有留言:
張貼留言