简体   繁体   English

使用无序列表扩展DIV

[英]Expanding a DIV with an Unordered List

I'm looking at having an unordered list that filters through some of my work. 我正在寻找一个无序列表来过滤我的一些工作。 I have the filter working perfectly fine (not in this example) and I am now at the stage where I am having difficulty styling it. 我的过滤器工作得很好(不是在这个例子中),我现在正处于我难以造型的阶段。 I've tried setting the width of the div and doing some online research but to no success. 我已经尝试设置div的宽度并进行一些在线研究,但没有成功。

It currently looks something like this: http://jsfiddle.net/XcVHU/ 它目前看起来像这样: http//jsfiddle.net/XcVHU/

What I am hoping for is that only two words are displayed initially (Filter and All) and when the user hovers over or clicks on the word "Filter", the list expands with a CSS width-transition to display the other categories (Web, Still, Motion and Games). 我希望的是,最初只显示两个单词(过滤器和全部),当用户将鼠标悬停或单击“过滤器”时,列表会以CSS宽度过渡扩展以显示其他类别(Web,还是,动作和游戏)。 So, from this: 所以,从这个:

Filter | 过滤| All 所有

to this: 对此:

Filter | 过滤| Web | 网络| Still | 还是| Motion | 动作| Games 游戏

It is better if you nest your ul 's such as... 如果你筑巢你的ul更好......

<div id="portfolionav">
    <ul class="filter">
        <li>Filter</li>
        <ul class="subfilters">
           <li class="web"><a href="#">Web</a></li>
           <li class="still"><a href="#">Still</a></li>
           <li class="motion"><a href="#">Motion</a></li>
           <li class="games"><a href="#">Games</a></li>
        </ul>
        <li class="current all"><a href="#">All</a></li>
    </ul>    
</div>​

The CSS changes for transitions are quite straightforward: 转换的CSS更改非常简单:

#portfolionav ul {
    display: inline-block;
    white-space: nowrap;
   -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    -o-transition: all 1s ease;
    -ms-transition: all 1s ease;
    transition: all 1s ease;

}
#portfolionav ul ul {width: 0; opacity: 0;}

#portfolionav ul:hover > ul {width: 370px; opacity: 1;}

http://jsfiddle.net/jukUm/ http://jsfiddle.net/jukUm/

UPDATE: 更新:

Here is final version with animation and fixed line-height bug: http://jsfiddle.net/XcVHU/9/ 这是动画和固定行高错误的最终版本: http//jsfiddle.net/XcVHU/9/

Another solution, without animation: 另一个没有动画的解决方案

http://jsfiddle.net/XcVHU/4/ http://jsfiddle.net/XcVHU/4/

What to do: 该怎么办:

  1. Put filters in separate nested UL 将过滤器放在单独的嵌套UL中
  2. Set it's display to inline. 将其显示设置为内联。
  3. On document ready hide filters 在文档准备隐藏过滤器
  4. On click toggle display property. 单击切换显示属性。

This solution is not buggy like the one provided by @PeterSzymkowski and looks nicer than @Duopixel's solution (which is anyway good and may be still suitable for you if you prefer animation of that kind when items appear outsite the right enge of the page and run into the position). 这个解决方案并不像@PeterSzymkowski提供的那样,并且看起来比@ Duopixel的解决方案更好(这无论如何都很好,如果您喜欢这种类型的动画,当项目出现在页面右侧并运行时,可能仍然适合您进入这个位置)。

UPDATE: 更新:

Here is animated version, few changes made, check here: 这是动画版本,进行了一些更改,请点击此处:

http://jsfiddle.net/XcVHU/7/ http://jsfiddle.net/XcVHU/7/

Split ul.filter into two ul 's and use some code: ul.filter拆分为两个ul并使用一些代码:

$('#expand').click(function(e){
    e.preventDefault();
    $('.filter.hidden').show();
    var tw = $('.filter.hidden').width();
    $('.filter.hidden').css('width', '0px');
    $('.filter.hidden').animate({width: tw+'px'});

});

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

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