How do I animate though a PNG sequence using jQuery (either by scrolling or triggered animation) [closed]

眉间皱痕 提交于 2020-01-22 08:07:09

问题


More and more I am seeing an effect where pngs are loaded into a series of DIVs (or one div) and then sequenced though frame by frame either based on button click or based on scroll. I've tried to peek at the code, and I understand that javascript is doing the heavy lifting, but I'm still a bit lost, are there any tutorials on this technique? examples?

example of animation (multiple div) http://atanaiplus.cz/index_en.html:

example of animation (one div): http://www.hyundai-veloster.eu/

example of scrolling animation: http://discover.store.sony.com/tablet/#design/ergonomics


回答1:


you just want to swap out the src attribute using a setInterval timer

var myAnim = setInterval(function(){
  $(".myImageHolder").attr('src', nextImage);
}, 42);

The trick is how you generate nextImage. This largely depends on the naming conventions of your images, or which direction you wish the animation to run in

Update

Or use a plugin




回答2:


Perhaps instead of switching between different images, use the spriting technique described in this question: How to show animated image from PNG image using javascript? [ like gmail ]



来源:https://stackoverflow.com/questions/9669805/how-do-i-animate-though-a-png-sequence-using-jquery-either-by-scrolling-or-trig

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