Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add scrollbar on dropdown menu options

I am trying to add a scrollbar to a dropdown menu options so when user clicks the menu it won't show all the options all the way till end. I tried

<select name='menu'>
  <option value='1'>first item</option>
  <option value='2'>second item</option>
  <option value='3'>third item</option>
  <option value='4'>fourth item</option>
  <option value='5'>fifth item</option>
  <option>........
  <option>........
  //I have many options.....
</select>

I try this css but it only works on the menu itself, not options.

select {
height:50px;
overflow-y: scroll;
}

Any thoughts? Thanks a lot.

like image 436
FlyingCat Avatar asked Mar 08 '12 20:03

FlyingCat


People also ask

How do I scroll through a drop down list?

Re: Drop down lists You can scroll a dropdown list up and down using the mouse scroll wheel. But to be able to use this option, you have to hover the mouse over the scroll bar instead of the list items.

How do I add a scrollbar to a list?

Drag the list object into the block. Select the block and in the properties pane, select "Size and Overflow". In the "Size and Overflow" window, set the desired dimensions of the block. Select the "Always use scrollbars" radio button.

How do I add a scroll bar to my UL tag?

Is there any way to add the scroll bar for it? A: You can try to add the scroll bar for submenu manually. For this purpose you should open your page where you added the css3menu in any text editor and add class="scroll" into the <ul></ul> tag.


2 Answers

give a css to your select like class="myDropDown" and add the following css

.myDropDown
{
   height: 50px;
   overflow: auto;
}

for reference: fiddle

like image 139
Jhankar Mahbub Avatar answered Oct 26 '22 20:10

Jhankar Mahbub


This is also I nice way of handeling it :)

http://css-tricks.com/long-dropdowns-solution/

From the link above:

var maxHeight = 400; $(function(){

$(".dropdown > li").hover(function() {

     var $container = $(this),
         $list = $container.find("ul"),
         $anchor = $container.find("a"),
         height = $list.height() * 1.1,       // make sure there is enough room at the bottom
         multiplier = height / maxHeight;     // needs to move faster if list is taller

    // need to save height here so it can revert on mouseout            
    $container.data("origHeight", $container.height());

    // so it can retain it's rollover color all the while the dropdown is open
    $anchor.addClass("hover");

    // make sure dropdown appears directly below parent list item    
    $list
        .show()
        .css({
            paddingTop: $container.data("origHeight")
        });

    // don't do any animation if list shorter than max
    if (multiplier > 1) {
        $container
            .css({
                height: maxHeight,
                overflow: "hidden"
            })
            .mousemove(function(e) {
                var offset = $container.offset();
                var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
                if (relativeY > $container.data("origHeight")) {
                    $list.css("top", -relativeY + $container.data("origHeight"));
                };
            });
    }

}, function() {

    var $el = $(this);

    // put things back to normal
    $el
        .height($(this).data("origHeight"))
        .find("ul")
        .css({ top: 0 })
        .hide()
        .end()
        .find("a")
        .removeClass("hover");

});

// Add down arrow only to menu items with submenus
$(".dropdown > li:has('ul')").each(function() {
    $(this).find("a:first").append("<img src='images/down-arrow.png' />");
});

});

like image 28
Magnus Karlsson Avatar answered Oct 26 '22 22:10

Magnus Karlsson