简体   繁体   English

如何:调整单个div的大小以适合容器,其中有一个类似div的图块

[英]How to: Resize a single div, to fit the container, where there is a tile of like divs

I have a container, full of little divs laid out in tiles. 我有一个装满瓷砖的小div容器。 My goal is to click a div, have it resize(animate) to match the container, then on a second click, it will contract back to its original size. 我的目标是单击一个div,使其调整大小(动画)以匹配容器,然后再次单击,它将收缩到其原始大小。

http://jsfiddle.net/taylorRichie/jXd5L/2/ http://jsfiddle.net/taylorRichie/jXd5L/2/

Jquery: jQuery:

$('#bio').click(function(){
    $('.tile').toggleClass("hidden");
    $('#bio').toggleClass("enlarged");
});

CSS: CSS:

#container{
    border:1px solid red;
    min-height:200px;
    width:400px;
    overflow:hidden;
    position:relative;
}

.tile{
    width: 90px;
    height: 90px;
    background-color: red;
    float:left;
    margin:5px;
    z-index:5;
    -webkit-transition:all 1300ms ease-in-out;
    -moz-transition:all 1300ms ease-in-out;
    -o-transition:all 1300ms ease-in-out;
    transition:all 1300ms ease-in-out;
}

.hidden{
    width: 0px;
    height: 0px;
    opacity: 0;
    position:relative;
    -webkit-transition:all 2300ms ease-in-out;
    -moz-transition:all 2300ms ease-in-out;
    -o-transition:all 2300ms ease-in-out;
    transition:all 2300ms ease-in-out;
}

#bio{
    background-color:#CCC;
} 

.enlarged{
    min-height:90px;
    height:100%;
    width:100%;
    opacity:1;
    position:absolute;
    z-index:20;
    -webkit-transition:all 1300ms ease-in-out;
    -moz-transition:all 1300ms ease-in-out;
    -o-transition:all 1300ms ease-in-out;
    transition:all 1300ms ease-in-out;
}

It's sort of working in chrome, but it's not clean, it's not fluid, a lot of shaking, and weirdness. 它有点像是在chrome中工作,但是它不干净,不流畅,晃动和怪异。

I would prefer the 'non-clicked' tiles to fade into the back, then fade back in when the original tile is closed. 我希望“非单击”磁贴淡入背面,然后在关闭原始磁贴时淡入。

I'm currently using a mix of CSS3 transitions and jquery for triggers, and toggles. 我目前正在使用CSS3过渡和jquery来混合触发器和切换。

Thanks! 谢谢!

Richie 里奇

++ UPDATE ++ ++更新++

Objective is to click a tile, have it expand to fit the container, then click again to have it return to its original position. 目的是单击一个图块,使其扩展以适合容器,然后再次单击以使其返回其原始位置。

This is just a prototype for testing an interaction, so I may be able to hard code the positions, but when it goes to production (not programmed by me) then it will be dynamic. 这只是用于测试交互的原型,因此我可以对位置进行硬编码,但是当它投入生产(不是我自己编程)时,它将是动态的。

I want the transitions to be fluid to give the user a sense of what's happening. 我希望过渡过程能够流畅,以使用户对正在发生的事情有所了解。

Each div will contain limited information prior to expansion, then the full info once it has completely expanded. 每个div在扩展之前将包含有限的信息,然后在完全扩展后包含完整的信息。

I've been doing so much design work, my dev work is suffering :) 我做了很多设计工作,我的开发工作很苦:)

Thanks for any help! 谢谢你的帮助!

Actually i think is bit hard to obtain a nice effect with what you have. 实际上,我认为很难用您所拥有的获得良好的效果。 Maybe you must use position: absolute; 也许您必须使用position: absolute; for your "enlarged" div and then you will get a lot of problems. 为您的“扩大”的div,那么您会遇到很多问题。

In my opinion the best way to animate them is to use jQuery, like i did here . 我认为,为它们设置动画的最佳方法是使用jQuery,就像我在这里所做的那样。

Actually you set .data() for current elements where you keep base width/height and then is a small step to play however you want with your animation. 实际上,您为当前元素设置了.data() ,在其中您保持基本宽度/高度,然后播放一小步,但是您想要使用动画。

You also can load some easings to make it more special. 您还可以加载一些缓动使其更特别。

I added if( t.is(':animated') ) return; 我添加了if( t.is(':animated') ) return; to avoid problems if users try to click while the animation is running 避免在动画运行时用户尝试单击的问题

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

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