(element, x, y, options)
| 12 | } |
| 13 | |
| 14 | function scrollToElement(element, x, y, options) { |
| 15 | options = options || {}; |
| 16 | |
| 17 | var start = scroll(element); |
| 18 | |
| 19 | var tween = Tween(start) |
| 20 | .ease(options.ease || 'out-circ') |
| 21 | .to({ top: y, left: x }) |
| 22 | .duration(options.duration || 1000); |
| 23 | |
| 24 | tween.update(function(o){ |
| 25 | element.scrollTop = o.top | 0; |
| 26 | element.scrollLeft = o.left | 0; |
| 27 | }); |
| 28 | |
| 29 | tween.on('end', function(){ |
| 30 | animate = function(){}; |
| 31 | }); |
| 32 | |
| 33 | function animate() { |
| 34 | raf(animate); |
| 35 | tween.update(); |
| 36 | } |
| 37 | |
| 38 | animate(); |
| 39 | |
| 40 | return tween; |
| 41 | } |
| 42 | |
| 43 | module.exports = scrollToElement; |
no test coverage detected