admin管理员组文章数量:1417097
I have created a small KineticJS animation, which you can see at this address:
.html
I would like to find a way for this animation to always be set to 100% of the window width. (It will be a "background" area for another element.)
I can do the initial set by setting the width to $(window).width() from jQuery (there are probably other ways of doing this, but jQuery will already be used), but I can't figure out how to redraw/reset the stage on resize or orientationchange.
So, is there a way to do any of the following to acplish this:
- Can I set the stage to a variable width somehow (100%)? (I'm assuming the answer is no, but even if it was yes, I'm not sure that the animation would be able to scale relatively anyway.)
- Can I just clear the animation and recreate it on resize or orientationchange? This doesn't sound like it'd be terribly efficient, and when I tried to use layer.remove() on resize and orientationchange, it nearly hung the browser.
- Or is there an easy way to convert this image to an SVG file and then use jQuery SVG instead to acplish the same thing? (Provided that everything still works on resize and orientationchange.)
- Or is there something else I'm not thinking of?
I have created a small KineticJS animation, which you can see at this address:
http://sandbox-ben.kimbiaservices./kineticjs/index.html
I would like to find a way for this animation to always be set to 100% of the window width. (It will be a "background" area for another element.)
I can do the initial set by setting the width to $(window).width() from jQuery (there are probably other ways of doing this, but jQuery will already be used), but I can't figure out how to redraw/reset the stage on resize or orientationchange.
So, is there a way to do any of the following to acplish this:
- Can I set the stage to a variable width somehow (100%)? (I'm assuming the answer is no, but even if it was yes, I'm not sure that the animation would be able to scale relatively anyway.)
- Can I just clear the animation and recreate it on resize or orientationchange? This doesn't sound like it'd be terribly efficient, and when I tried to use layer.remove() on resize and orientationchange, it nearly hung the browser.
- Or is there an easy way to convert this image to an SVG file and then use jQuery SVG instead to acplish the same thing? (Provided that everything still works on resize and orientationchange.)
- Or is there something else I'm not thinking of?
1 Answer
Reset to default 8I think I found the solution. The problem with trying to detect .on('resize')
is that the act of resizing a window causes the event to fire a zillion times, which drags the browser down.
Inspired by this answer: Detect when a window is resized using JavaScript ? -- I was able to create a jQuery event that detects (more or less) when the resize is pleted. Once that's done, I empty the container element and refire the initial draw script. The code below does the trick:
$(window).on('resize',function(){
if(this.resizeTO) clearTimeout(this.resizeTO);
this.resizeTO = setTimeout(function(){
$(this).trigger('resizeEnd');
},500);
});
$(window).on('resizeEnd orientationchange',function(){
$('#container').empty();
RunHeaderAnim();
});
本文标签: javascriptMaking KineticJS stage of variable width OR update stage on resizeStack Overflow
版权声明:本文标题:javascript - Making KineticJS stage of variable width OR update stage on resize - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745239884a2649263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论