-1

I'm trying to create a menu that works like the select menus on iOS7. I've been using jQuery but I haven't been able to get it to work smoothly and look nice.

Has anyone managed to do this or do you know of anywhere else it has been done so I can see an example?

Here is what I'm trying to create: enter image description here

This is the iOS7 select menu: enter image description here

stuartb
  • 335
  • 1
  • 4
  • 17
  • you say you have used jQuery to get there, but it wasn't running properly. Please share a JSFiddle with your work so far – Ben Philipp May 19 '15 at 22:44

1 Answers1

2

Well, this is a rather complex project since it involves quite a few different things, and you haven't provided any code (yet).

So here are some ideas that might push your project into the right direction:

depending on how your list items are created, give them something indicating their place in the list (like in my IDs here: id="item-1" etc.)

Then, on hover, go through the list items and work out how far away they are from the selected one, using for example Math.abs(selectedNumber - listItemNumber) And then apply your style changes, scaled by how far away the items are.

Here is an example: 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>

This uses simply font-size and margins so far, but you should get the idea.

alternatively I also tried transform: scale(), but surprisingly, that did not work as smoothly: https://jsfiddle.net/svArtist/entw3mp1/

Ben Philipp
  • 1,832
  • 1
  • 14
  • 29
  • Nice answer, it looks like you put a bit of thought into it. I should have mentioned I intended the active list item to stay cantered vertically and the options would scroll up and down. It's going to be controlled using the arrow keys. – stuartb May 21 '15 at 02:27