创建看起来像iOS7选择菜单的菜单

时间:2015-05-19 22:38:09

标签: jquery css ios7 menu animated

我正在尝试创建一个与iOS7上的选择菜单类似的菜单。我一直在使用jQuery,但是我无法让它顺利运行并且看起来不错。

有没有人设法做到这一点,或者你知道其他地方已经完成了所以我能看到一个例子吗?

以下是我要创建的内容: enter image description here

这是iOS7选择菜单: enter image description here

1 个答案:

答案 0 :(得分:2)

嗯,这是一个相当复杂的项目,因为它涉及很多不同的事情,而且你还没有提供任何代码。

所以这里有一些想法可能会推动您的项目朝着正确的方向发展:

取决于您的列表项的创建方式,在列表中给出指示其位置的内容(例如我的ID:id="item-1"等。)

然后,在悬停时,浏览列表项并使用例如Math.abs(selectedNumber - listItemNumber)计算它们与所选项目的距离 然后应用您的样式更改,根据项目的距离进行缩放。

这是一个例子: https://jsfiddle.net/svArtist/7fgqu428/



$(".item").hover(function(){
   var curnum = $(this).attr("id").split("-").pop();
    scaleItems(curnum);
}, function(){
reset();
});

function scaleItems(itemNum){
      $(".item").each(function(){
        var thisnum = $(this).attr("id").split("-").pop();
         
        $(this).css("font-size", (10+25/(1+Math.abs(itemNum - thisnum)))+"px");
        $(this).css("padding", (10+10/(1+Math.abs(itemNum - thisnum)))+"px 20px");
    });
}

function reset(){
      $(".item").each(function(){
        $(this).css("font-size", "20px");
        $(this).css("padding", "20px");
    });
}

html{
    height:100%;
}
body{
    margin:0;
    height:100%;
}
#wrapper{
    height:100%;
    background-color:#888;
}
#menu{
    height:100%;
    overflow-y:auto;
    position:absolute;
    left:0;
    padding: 20px;
    box-sizing:border-box;
    background-color: rgba(255,255,255,0.5);
}
.item{
    padding:20px;
    font-family:Arial, sans-serif;
    font-size:20px;
    font-weight:300;
    border-bottom:1px solid #888;
    cursor:pointer;
    white-space: nowrap;
}

*{
    transition: all 0.5s;
}

.item:hover{
    font-size: 30px;
    font-weight:600;
    background:#fff;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">
    <div id="menu">
        <div id="item-1" class="item">
            Item 1 asdfsf djfkdjf
        </div>
        <div id="item-2" class="item">
            Item 2 asdfsf djfkdjf
        </div>
        <div id="item-3" class="item">
            Item 3 lköjhkghf dghggjkx dcd
        </div>
        <div id="item-4" class="item">
            Item 4 agh fkdjf
        </div>
        <div id="item-5" class="item">
            Item 5 dfggds soidfhsd fsss
        </div>
        <div id="item-6" class="item">
            Item 6 asdfsf djfkdjf
        </div>
        <div id="item-7" class="item">
            Item 7 dfg dg jfhfgh sfdgh
        </div>
    </div>
</div>
&#13;
&#13;
&#13;

到目前为止,它只使用了font-sizemargin,但您应该明白这一点。

或者我也试过了transform: scale(),但令人惊讶的是,这并不顺利: https://jsfiddle.net/svArtist/entw3mp1/