Changeset 19846
- Timestamp:
- 02/06/2012 11:17:28 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/admin-bar.dev.js
r19712 r19846 60 60 }); 61 61 62 $('#wpadminbar').click( function(e) { 63 if ( e.target.id != 'wpadminbar' && e.target.id != 'wp-admin-bar-top-secondary' ) 64 return; 65 66 e.preventDefault(); 67 $('html, body').animate({ scrollTop: 0 }, 'fast'); 68 }); 69 62 70 }); 63 71 } else { … … 179 187 } 180 188 return false; 189 }, 190 191 scrollToTop = function(t) { 192 var distance, speed, step, steps, timer, speed_step; 193 194 // Ensure that the #wpadminbar was the target of the click. 195 if ( t.id != 'wpadminbar' && t.id != 'wp-admin-bar-top-secondary' ) 196 return; 197 198 distance = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; 199 200 if ( distance < 1 ) 201 return; 202 203 speed_step = distance > 800 ? 130 : 100; 204 speed = Math.min( 12, Math.round( distance / speed_step ) ); 205 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 ); 206 steps = []; 207 timer = 0; 208 209 // Animate scrolling to the top of the page by generating steps to 210 // the top of the page and shifting to each step at a set interval. 211 while ( distance ) { 212 distance -= step; 213 if ( distance < 0 ) 214 distance = 0; 215 steps.push( distance ); 216 217 setTimeout( function() { 218 window.scrollTo( 0, steps.shift() ); 219 }, timer * speed ); 220 221 timer++; 222 } 181 223 }; 182 224 … … 199 241 200 242 addEvent(aB, 'click', clickShortlink ); 243 244 addEvent(aB, 'click', function(e) { 245 scrollToTop( e.target || e.srcElement ); 246 }); 201 247 } 202 248
Note: See TracChangeset
for help on using the changeset viewer.