| 190 | scrollToTop = function(t) { |
| 191 | if(t.id != 'wpadminbar') return; |
| 192 | |
| 193 | var startY = (function() { |
| 194 | if (self.pageYOffset) return self.pageYOffset; |
| 195 | |
| 196 | if (document.body.scrollTop) return document.body.scrollTop; |
| 197 | |
| 198 | return 0; |
| 199 | })(), |
| 200 | distance = startY > 0 ? startY : -startY; |
| 201 | |
| 202 | if (distance < 100) { |
| 203 | scrollTo(0, 0); return; |
| 204 | } |
| 205 | |
| 206 | var speed = Math.round(distance / 100), |
| 207 | step = Math.round(distance / 25), |
| 208 | leapY = startY > 0 ? startY - step : startY + step, |
| 209 | timer = 0; |
| 210 | |
| 211 | speed = (speed >= 20) ? 20 : speed; |
| 212 | |
| 213 | if (0 > startY) { |
| 214 | for ( var i = startY; i < 0; i += step ) { |
| 215 | setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed); |
| 216 | leapY += step; |
| 217 | |
| 218 | if (leapY > 0) { |
| 219 | leapY = 0; |
| 220 | } |
| 221 | |
| 222 | timer++; |
| 223 | } |
| 224 | |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | for ( var i = startY; i > 0; i -= step ) { |
| 229 | setTimeout("window.scrollTo(0, " + leapY + ")", timer * speed); |
| 230 | leapY -= step; |
| 231 | |
| 232 | if (leapY < 0) { |
| 233 | leapY = 0; |
| 234 | } |
| 235 | |
| 236 | timer++; |
| 237 | } |
| 238 | }; |
| 239 | |