html5 浮动侧滑菜单栏怎样实现

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html5 浮动侧滑菜单栏怎样实现相关的知识,希望对你有一定的参考价值。

参考技术A 一共有4种侧滑动画特效。这款CSS3菜单的特点是鼠标划过时即可以各种动画方式展开和隐藏菜单项,该动画方式由CSS3中的transition-delay属性来完成
<style type="text/css">

/*Fontawesome Iconfont*/

@import url(http://libs.useso.com/js/font-awesome/4.0.1/css/font-awesome.min.css);

@import url(http://fonts.useso.com/css?family=Montserrat);

* margin: 0; padding: 0;

li list-style-type: none;

.grid float: left;width:980px;margin: 0 auto;

.grid > li width: 285px; height: 500px; overflow: hidden; float: left; margin: 20px 0 20px 30px; position: relative;

.grid > li:hover box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.5);

.grid>li section position: relative; transition: all 0.25s; width: 100%;

.grid>li h2 font: bold 14px montserrat; color: #fff; text-transform: uppercase; position: absolute; text-align: center; width: 60%; left: 20%; top: 100px; padding: 10px 0; border: 2px solid white; border-radius: 4px;

.sidenav position: absolute; top: 0; left: 0; bottom: 0; background: linear-gradient(rgba(50,60,60, 1), rgba(50,60,60, 0.7)); width: 50px; transition: all 0.25s; overflow: hidden; padding-top: 100px;

.sidenav li _overflow: hidden; width: 150px;

.sidenav a text-decoration: none; color: #eee; display: block; line-height: 48px;

.sidenav span display: block;

.sidenav b padding-left 10px; display: block; color: white; font-family: Montserrat; font-size: 12px; line-height: 4; opacity: 0;

.sidenav a i display: block; float: left; font-size: 16px; line-height: 48px; width: 50px; text-align: center;

/*All instances*/

.grid>li:hover .sidenav width: 150px;

.grid>li:hover section margin-left: 150px;

.grid>li:hover b opacity: 1;

.sidenav li:nth-child(1) b, .sidenav li:nth-child(1) a transition-delay: .08s;

.sidenav li:nth-child(2) b, .sidenav li:nth-child(2) a transition-delay: .16s;

.sidenav li:nth-child(3) b, .sidenav li:nth-child(3) a transition-delay: .24s;

.sidenav li:nth-child(4) b, .sidenav li:nth-child(4) a transition-delay: .32s;

.sidenav li:nth-child(5) b, .sidenav li:nth-child(5) a transition-delay: .40s;

.sidenav li:nth-child(6) b, .sidenav li:nth-child(6) a transition-delay: .48s;

/*Three*/

.three .w transform: perspective(100px) translateZ(-24px);

.three b transform: perspective(100px) rotateY(180deg) translateZ(24px) scale(0.5);

.three:hover b transform: perspective(100px) rotateY(0) translateZ(24px) scale(1); transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275); background: transparent;

.three .sidenav width: 150px;

/*Two*/

.two .w transform: perspective(100px) translateZ(-24px);

.two b transform: perspective(100px) rotateX(90deg) translateZ(24px) scale(1.5); opacity: 0;

.two:hover b transform: perspective(100px) rotateX(0) translateZ(24px) scale(1); transition: all .4s; opacity: 1;

.two .sidenav width: 150px;

/*One*/

.one .w transform: perspective(100px);

.one b transform: perspective(100px) rotateY(90deg); _opacity: 0; transform-origin: left center; _border: 1px solid white;

.one:hover b transform: perspective(100px) rotateX(0); transition: all .4s; opacity: 1;

.one .sidenav width: 150px;

.one .sidenav span float: left; width: 100px;

</style>

<!--[if IE]>

<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>

<![endif]-->

</head>

<body>

<div class="htmleaf-container">

<header class="htmleaf-header bgcolor-11">

<div class="htmleaf-demo center">

<a href="index.html">DEMO1</a>

<a href="index2.html" class="current">DEMO2</a>

<a href="index3.html">DEMO3</a>

<a href="index4.html">DEMO4</a>

</div>

<div style="text-align:center;clear:both;">

<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>

<script src="/follow.js" type="text/javascript"></script>

</div>

</header>

<div class="htmleaf-content bgcolor-8">

<ul class="grid">

<li class="one">

<ul class="sidenav">

<li><a><i class="fa fa-check"></i><span class="w"><b>Tasks</b></span></a></li>

<li><a><i class="fa fa-inbox"></i><span class="w"><b>Messages</b></span></a></li>

<li><a><i class="fa fa-pencil"></i><span class="w"><b>New Post</b></span></a></li>

<li><a><i class="fa fa-cog"></i><span class="w"><b>Settings</b></span></a></li>

<li><a><i class="fa fa-star"></i><span class="w"><b>Starred</b></span></a></li>

<li><a><i class="fa fa-power-off"></i><span class="w"><b>Logout</b></span></a></li>

</ul>

<section>

<h2>Door Opening</h2>

<img src="img/mb1.png"/>

</section>

</li>

<li class="two">

<ul class="sidenav">

<li><a><i class="fa fa-check"></i><span class="w"><b>Tasks</b></span></a></li>

<li><a><i class="fa fa-inbox"></i><span class="w"><b>Messages</b></span></a></li>

<li><a><i class="fa fa-pencil"></i><span class="w"><b>New Post</b></span></a></li>

<li><a><i class="fa fa-cog"></i><span class="w"><b>Settings</b></span></a></li>

<li><a><i class="fa fa-star"></i><span class="w"><b>Starred</b></span></a></li>

<li><a><i class="fa fa-power-off"></i><span class="w"><b>Logout</b></span></a></li>

</ul>

<section>

<h2>Flip Down</h2>

<img src="img/mb2.png"/>

</section>

</li>

<li class="three">

<ul class="sidenav">

<li><a><i class="fa fa-check"></i><span class="w"><b>Tasks</b></span></a></li>

<li><a><i class="fa fa-inbox"></i><span class="w"><b>Messages</b></span></a></li>

<li><a><i class="fa fa-pencil"></i><span class="w"><b>New Post</b></span></a></li>

<li><a><i class="fa fa-cog"></i><span class="w"><b>Settings</b></span></a></li>

<li><a><i class="fa fa-star"></i><span class="w"><b>Starred</b></span></a></li>

<li><a><i class="fa fa-power-off"></i><span class="w"><b>Logout</b></span></a></li>

</ul>

IOS开发UI篇--一个侧滑菜单SlidingMenu

一、简介

侧滑菜单已经成为app一个极常用的设计,不管是事务类,效率类还是生活类app。侧滑菜单因Path 2.0和Facebook为开发者熟知,国内目前也有很多流行app用到了侧滑菜单,比如QQ、网易邮箱、知乎等等。
iOS官方并没有提供类似于侧滑栏之类的组件,所以我们需要自己写一个侧滑栏控件,为了不要重复造轮子,我在github上找到了一个使用简单方便,新手容易入手的侧滑菜单控件,地址:https://github.com/John-Lluch/SWRevealViewController/tree/master/

下面我们就是使用上面的控件,来做一个侧滑栏的小Demo,来教大家快速入门侧滑栏控件。
Demo界面演示如下:

技术分享 

二、使用说明

第一步:导入SWRevealViewController.h和SWRevealViewController.m文件

第二步:编写中间显示界面CenterViewController

在viewDidLoad方法中设置SWRevealViewController中的panGestureRecognizer方法,即可实现在主界面上滑动就可以出现左侧或者右侧菜单。设置revealToggle:方法就可以实现点击进行左边菜单和中间界面的切换。设置rightRevealToggle:方法就可以实现右边菜单和中间界面的切换。下面就是中间界面的相关代码:

   //注册该页面可以执行滑动切换
    SWRevealViewController *revealController = self.revealViewController;
    [self.view addGestureRecognizer:revealController.panGestureRecognizer];

    // 注册该页面可以执行点击切换
    [leftBtn addTarget:revealController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn addTarget:revealController action:@selector(rightRevealToggle:) forControlEvents:UIControlEventTouchUpInside];

 

第三步、编写左侧菜单栏LeftViewController

左侧菜单栏是由一个UITableView组成的,我们在每个cell的点击方法中执行 [revealViewController pushFrontViewController:viewController animated:YES];切换中间界面的操作。代码如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SWRevealViewController *revealViewController = self.revealViewController;
    UIViewController *viewController;

    switch (indexPath.row) {
        case 0:
            viewController = [[CenterView1Controller alloc] init];
            break;
        case 1:
            viewController = [[CenterView2Controller alloc] init];
            break;

        default:
            break;
    }
    [revealViewController pushFrontViewController:viewController animated:YES];

}

 

第四步、编写右侧菜单栏RightViewController

这里主要演示左侧菜单栏,这里就不做过多描述。就以一个简单的ViewController代替。

第五步、在AppDelegate.m文件中的- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions方法中配置以上界面,可以分别设置左侧菜单栏、右侧菜单栏和中间首页。

详见代码注释:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //左侧菜单栏
    LeftViewController *leftViewController = [[LeftViewController alloc] init];

    //首页
    CenterView1Controller *centerView1Controller = [[CenterView1Controller alloc] init];

    //右侧菜单栏
    RightViewController *rightViewController = [[RightViewController alloc] init];

    SWRevealViewController *revealViewController = [[SWRevealViewController alloc] initWithRearViewController:leftViewController frontViewController:centerView1Controller];
    revealViewController.rightViewController = rightViewController;

    //浮动层离左边距的宽度
    revealViewController.rearViewRevealWidth = 230;
    //    revealViewController.rightViewRevealWidth = 230;

    //是否让浮动层弹回原位
    //mainRevealController.bounceBackOnOverdraw = NO;
    [revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];

    self.window.rootViewController = revealViewController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

 

三、总结

接下来准备使用这个界面作为主框架,写一系列关于IOS动画的总结 和 facebook开源动画项目pop动画的使用的博客。敬请期待。

四、下载地址

github下载地址:https://github.com/yixiangboy/IOSAnimationDemo

如果觉得对你还有些用,给一颗star吧。你的支持是我继续的动力。


博主的话

以前看过很多别人的博客,学到不少东西。现在准备自己也开始写写博客,希望能够帮到一些人。 
我的联系方式: 
微博:新浪微博 
博客:http://blog.csdn.net/yixiangboy 
github:https://github.com/yixiangboy

以上是关于html5 浮动侧滑菜单栏怎样实现的主要内容,如果未能解决你的问题,请参考以下文章

android 怎样让drawerlayout设置的侧滑菜单的内容充满屏幕

Android Studio实现侧滑菜单(最佳)

IOS开发UI篇--一个侧滑菜单SlidingMenu

mui侧滑菜单"点击含有mui-action-menu类的控件"无法实现侧滑

Android自定义顶部栏及侧滑菜单和fragment+viewpag滑动切换的实现

Flutter:手把手教你实现一个仿QQ侧滑菜单