How to follow YUI driven animation off screen or center viewport on item?

亡梦爱人 提交于 2019-12-11 11:55:37

问题


I'm using code adapted from the YUI3 documentation example to animate a graphic along a curved path.

The full canvas size is intentionally pretty huge - definitely larger than most screens - so the graphic will run out of viewport space pretty quickly and animate off the screen.

Instead, I'd like browser viewport to follow or centre on the image so that it stays 'in shot'.

Is there a YUI fuelled way of doing this? Or something simpler?


回答1:


You could do something like this, basically just makes sure the viewport is always tracking an object on the canvas by taking into account the canvas coordinates in relation to the page.

function track(x,y, offsetX, offsetY){
    var trackX = x - (canvas.offsetLeft + offsetX);
        trackY = y - (canvas.offsetTop + offsetY);

    window.scrollTo(trackX, trackY);

}

Live Demo



来源:https://stackoverflow.com/questions/12392455/how-to-follow-yui-driven-animation-off-screen-or-center-viewport-on-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!