简体   繁体   English

CSS:制作水平滚动菜单

[英]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. 假设有6个菜单图标,一次显示3个。 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. 如果我的屏幕与菜单4相关,则必须放置menu4。


 <   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 更新适用于MouseOver的js

<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 JSFiddle

Check here 在这里检查

Update3 更新3

雅虎导航

Update 4 更新4

This is dynamic menu retreived from db build with ul & li's. 这是从ul&li's的db build中获取的动态菜单。 If there is more Li than screen width, I simply want an arrow to left & right side to scroll extra li's, if any. 如果Li大于屏幕宽度,我只希望左右箭头滚动其他li(如果有)。

See this fiddle: 看到这个小提琴:

http://jsfiddle.net/kzQFQ/49/ 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'
    });
    }
});    
});

Good article about horizontal scrollable menu here 关于水平滚动菜单的好文章在这里

And DEMO (Note: Reduce the size of the browser) DEMO (注意:减小浏览器的大小)

hop this should be help you see link 希望对您有所帮助,请参阅链接

http://jquery.malsup.com/cycle/int2.html http://jquery.malsup.com/cycle/int2.html

see Non-Image Content at the last of page 请参阅页面最后的非图片内容

see this fiddle: http://fiddle.jshell.net/vac9x/1/ 看到这个小提琴: http : //fiddle.jshell.net/vac9x/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM