简体   繁体   English

更改表格宽度动画

[英]Change table width animation

Is it possible to smoothly animate the width of a table. 是否可以平滑地动画化桌子的宽度。 Ten percent per second would be a good rate. 每秒百分之十将是一个很好的速度。 So that it slowly expands and keeps expanding? 这样它才能缓慢扩展并不断扩展?

On load <table id="01" width="80%" height="769"> 加载时<table id="01" width="80%" height="769">

1 second <table id="01" width="90%" height="769"> 1秒<table id="01" width="90%" height="769">

2 second <table id="01" width="100%" height="769"> 2秒<table id="01" width="100%" height="769">

3 second <table id="01" width="110%" height="769"> 3秒<table id="01" width="110%" height="769">

There are several ways to do so. 有几种方法可以这样做。 If you are willing to assume html5 supporting browsers, check out css transformations and transitions. 如果您愿意使用支持html5的浏览器,请查看CSS转换和转换。 Transitions are easier to use for what you need. 转换可轻松满足您的需求。 you can define you css like this: 你可以这样定义你的css:

#01 {
    -moz-transition : width 3s; /* Firefox */
    -webkit-transition : width 3s; /* chrome and safari */
    -o-transition: width 3s; /* Opera */
    transition: width 3s;
    width : 80%;
}
#01.growing {
    width : 110%
}

Then when you want the transition to start, just add the class "growing" to the element. 然后,当您要开始过渡时,只需将“增长”类添加到元素中。

Here is an example 这是一个例子

In JQuery you can chain .animate() s to get what you want: JQuery您可以链接.animate()以获得所需的内容:

$('#table').animate({width: '+=' + $(this).width() * 0.1 + 'px'}, 1000).animate({width: '+=' + $(this).width() * 0.1 + 'px'}, 1000).animate({width: '+=' + $(this).width() * 0.1 + 'px'}, 1000).animate({width: '+=' + $(this).width() * 0.1 + 'px'}, 1000);

and if you want to increase the size in one step (ie. without delay): 如果您要一步一步增加大小(即不加延迟):

$('#table').animate({width: $(this).width() * 1.1 + 'px'}, 4000);

Here is a demo . 这是一个演示

Yes it is possible! 对的,这是可能的! (easiest answer all day!) (整天最简单的答案!)

but seriously.. look into javascript smooth resizing? 但认真..研究javascript平滑调整大小? or if you want to use a library there are MANY MANY ui plugins that will do this for most major libraries.. 或者,如果您想使用一个库,则有很多很多ui插件可以对大多数主要库执行此操作。

jQuery is the obvious choice for most... however for something this simple I suggest looking into how to do it yourself. jQuery是大多数人的明显选择...但是对于这种简单的事情,我建议您自己研究如何做。

here is a quick example in jQuery 是jQuery中的一个简单示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM