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

标签 jquery css ios7 menu animated

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

有没有人设法做到这一点,或者您是否知道其他任何地方已经做到这一点,以便我可以看到一个例子?

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

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

最佳答案

好吧,这是一个相当复杂的元素,因为它涉及很多不同的东西,而且您还没有提供任何代码(还)。

因此,这里有一些想法可能会将您的元素推向正确的方向:

根据您的列表项是如何创建的,给它们一些指示它们在列表中的位置的东西(就像我在这里的 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>

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

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

关于jquery - 创建看起来像 iOS7 选择菜单的菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30337354/

相关文章:

css - 为什么 z-index 对这两个元素不起作用?

ios - 尝试在 Garageband 中使用已发布的应用间音频应用程序时出错

javascript - 位置 :fixed(css) behaving differently in different browser

jquery - 使用 DT::datatable 为用户调整列大小

JQuery:简单幻灯片的问题

ios - 应用程序在 iOS 5、iOS 6 上运行,但在 iOS 7 上崩溃

iphone - 在 UITableView 中删除行时出错(仅在 iOS7 中)

javascript - 如何使用.ajax查询多个GitHub url,然后对结果进行排序?

javascript - 从另一个 div 的内部拖放一个 div

html - 将 div 放在居中的图像顶部