admin管理员组文章数量:1401199
KnockoutJS has been really great to use so far, but I'm new to the framework. I'm trying to create a tabbed sort of interface, e.g. 4 links and a mon display area. Clicking on a link takes advantage of Knockout's templating system and will switch the template. This has been working great, but I want to add some kind of animation in between the template switching.
How can I acplish this? I've read a little bit about beforeRemove/afterAdd, but this only seems to apply to observableArrays. I know KnockoutJS supports animations/custom bindings (I'm using them more straightforwardly for other elements on my page).
If my whole approach is incorrect, is there a better way to do a tabbed interface to easily get transitions?
Here is my code right now.
The HTML:
<div class="Page">
<span data-bind="template: {name: current_page()}"></span>
</div>
<script type="text/html" id="Home">
<!-- Home content -->
</script>
<script type="text/html" id="Tab1">
<!-- Tab1 content -->
</script>
The Javascript (Knockout's ViewModel):
this.current_page = ko.observable("Home")
//later on...
this.current_page("Tab1");
KnockoutJS has been really great to use so far, but I'm new to the framework. I'm trying to create a tabbed sort of interface, e.g. 4 links and a mon display area. Clicking on a link takes advantage of Knockout's templating system and will switch the template. This has been working great, but I want to add some kind of animation in between the template switching.
How can I acplish this? I've read a little bit about beforeRemove/afterAdd, but this only seems to apply to observableArrays. I know KnockoutJS supports animations/custom bindings (I'm using them more straightforwardly for other elements on my page).
If my whole approach is incorrect, is there a better way to do a tabbed interface to easily get transitions?
Here is my code right now.
The HTML:
<div class="Page">
<span data-bind="template: {name: current_page()}"></span>
</div>
<script type="text/html" id="Home">
<!-- Home content -->
</script>
<script type="text/html" id="Tab1">
<!-- Tab1 content -->
</script>
The Javascript (Knockout's ViewModel):
this.current_page = ko.observable("Home")
//later on...
this.current_page("Tab1");
Share
Improve this question
asked May 28, 2012 at 18:08
SharkCopSharkCop
1,1202 gold badges13 silver badges19 bronze badges
1 Answer
Reset to default 9You can use the afterRender
property of the template binding:
<span data-bind="template: {name: current_page(), afterRender: animatePageChange }"></span>
.. and then on your view model you can add whatever animation you fancy:
animatePageChange: function() { $('#content').hide(); $('#content').fadeIn(3000); }
I have put together a simple demo at http://jsfiddle/unklefolk/v3JMS/1/
本文标签: javascriptKnockoutjsTransitions between dynamic template switchingStack Overflow
版权声明:本文标题:javascript - Knockoutjs - Transitions between dynamic template switching? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744217251a2595695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论