Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Making Horizontal scrollable Menu

I want to add a menu to my application screens. The menu will have the menu icons which are horizontal scroll-able one menu at a time when left or right arrow pressed. Based on the menu screen the menu should be scrolled to that menu icon for that menu screen.

Ex.:


 <   menu1     |  menu2  |   menu3   >

Say there are 6 menu icons and 3 are visible at a time. on press of right arrow, it should scroll one item at a time.

and if my screen is related to menu 4, the menu4 has to be positioned.


 <   menu4     |  menu5  |   menu6   >

And also each menu item should be clickable.

Please let me know, How I can achieve this.

Update Have js for MouseOver

<script type="text/javascript">
    $(function () {
        var div = $('div.sc_menu'),
             ul = $('ul.sc_menu'),
             ulPadding = 15;
        var divWidth = div.width();
        div.css({ overflow: 'hidden' });
        var lastLi = ul.find('li:last-child');
        div.mousemove(function (e) {
            var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

            var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth;
            div.scrollLeft(left);
        });
    });
</script>

JSFiddle

Check here

Update3

Yahoo's Navigation

Update 4

This is dynamic menu retreived from db build with ul & li's. If there is more Li than screen width, I simply want an arrow to left & right side to scroll extra li's, if any.

like image 997
صفي Avatar asked Nov 30 '13 05:11

صفي


People also ask

How do I add a horizontal scroll bar in CSS?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.

Does scrollIntoView work horizontally?

((JavascriptExecutor) driver). executeScript("arguments[0]. scrollIntoView(true);", element); This works for vertical scrolling but not for horizontal.


2 Answers

See this fiddle:

http://jsfiddle.net/kzQFQ/49/

$(document).ready(function () {
$('.right').click(function () {
    var position = $('.container').position();
    var r=position.left-$(window).width()
    $('.container').animate({
        'left': ''+r+'px'
    });
});    

$('.left').click(function () {
    var position = $('.container').position();
    var l=position.left+$(window).width()
    if(l<=0)
    {
    $('.container').animate({
        'left': ''+l+'px'
    });
    }
});    
});
like image 182
Zword Avatar answered Oct 05 '22 00:10

Zword


Good article about horizontal scrollable menu here

And DEMO (Note: Reduce the size of the browser)

like image 27
isxaker Avatar answered Oct 05 '22 01:10

isxaker