css菜单上滑的效果_创建CSS3滑出菜单#5

css菜单上滑的效果

Creating CSS3 Slideout Menu #5
Creating CSS3 Slideout Menu #5

CSS3 slideout menu tutorial. This is our fifth CSS3 menu. This will nice slideout menu with fading images (animated with transition effects). Make attention, that all these new effects (transitions) will work only in most fresh browsers like FF, Chrome, Safary browsers (possible in Opera too). But not in IE (transitions still not available here). I just added few hacks for IE – so menu will work here too (but not so smooth). Anyway – lets test our new menu.

CSS3滑出菜单教程。 这是我们的第五个CSS3菜单。 这将是带有褪色图像(带有过渡效果动画)的漂亮的滑出菜单。 请注意,所有这些新效果(转换)仅在大多数新的浏览器(例如FF,Chrome,Safary浏览器(在Opera中也可能))中起作用。 但是在IE中不可用(转换在这里仍然不可用)。 我刚刚为IE添加了一些技巧-因此菜单也可以在这里使用(但不太流畅)。 无论如何-让我们测试新菜单。

Here are final result (what we will creating):

这是最终结果(我们将创建的结果):

css3 menu5

CSS3菜单5

Here are samples and downloadable package:

以下是示例和可下载的软件包:

现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

Ok, download our example files (package) and lets start making this menu!

好的,下载示例文件(包),然后开始制作此菜单!

步骤1. HTML (Step 1. HTML)

Here are html source of our menu. As you can see – here we can assign URL, title, and description to each link.

这是我们菜单的html源码。 如您所见–在这里,我们可以为每个链接分配URL,标题和描述。

index.html (index.html)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <title>CSS3 slideout menu #5</title>
</head>
<body>
<div class="example">
    <ul class="nav">
        <li>
        <!--[if lte IE 6]><a class="ie6" href="#url"><table><tr><td><![endif]-->
            <ul class="sub">
                <li><a href="https://www.script-tutorials.com/"><b>Home</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/category/html-css/"><b>Tutorials</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/category/resources/"><b>Resources</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/about/"><b>About</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/creating-css3-slideout-menu-5/"><b>Back</b><p>custom description here</p><i></i></a></li>
            </ul>
        <!--[if lte IE 6]></td></tr></table></a><![endif]-->
        </li>
    </ul>
    <div style="clear:both"></div>
</div>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <title>CSS3 slideout menu #5</title>
</head>
<body>
<div class="example">
    <ul class="nav">
        <li>
        <!--[if lte IE 6]><a class="ie6" href="#url"><table><tr><td><![endif]-->
            <ul class="sub">
                <li><a href="https://www.script-tutorials.com/"><b>Home</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/category/html-css/"><b>Tutorials</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/category/resources/"><b>Resources</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/about/"><b>About</b><p>custom description here</p><i></i></a></li>
                <li><a href="https://www.script-tutorials.com/creating-css3-slideout-menu-5/"><b>Back</b><p>custom description here</p><i></i></a></li>
            </ul>
        <!--[if lte IE 6]></td></tr></table></a><![endif]-->
        </li>
    </ul>
    <div style="clear:both"></div>
</div>
</body>
</html>

步骤2. CSS (Step 2. CSS)

Here are used CSS styles. First two selectors (you can skip it) belong to our demo page. All rest – menu #5 styles.

这是使用CSS样式。 前两个选择器(您可以跳过它)属于我们的演示页面。 所有其他–菜单5样式。

css / style.css (css/style.css)

/* demo page styles */
body {
    background:#eee;
    margin:0;
    padding:0;
    font-family: "Trebuchet MS",Arial,Helvetica,sans-serif;
}
.example {
    position:relative;
    background:#fff url(../images/background.jpg);
    width:650px;
    height:382px;
    border:1px #000 solid;
    margin:20px auto;
    border-radius:3px;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
}
/* main menu styles */
ul.nav {
    list-style:none;
    height:120px;
    margin:0;
    padding:0;
}
ul.nav table {
    border-collapse:collapse;
    width:0;
    height:0;
    margin:-1px 0 -5px -1px;
}
ul.nav > li {
    float:right;
    height:120px;
    width:40px;
    position:relative;
    overflow:hidden;
    -webkit-transition-duration:.5s;
    -moz-transition-duration:.5s;
    -o-transition-duration:.5s;
}
* html ul.nav > li {
    width:auto;
}
ul.nav > li a.ie6 {
    float:left;
    height:120px;
    width:39px;
    position:relative;
    overflow:hidden;
}
ul.sub {
    list-style:none;
    height:120px;
    width:600px;
    background:url(../images/panel.png) no-repeat right top;
    position:absolute;
    left:0;
    top:0;
    margin:0;
    padding:0;
}
ul.sub li {
    float:left;
}
ul.sub li:first-child {
    margin-left:45px;
}
ul.sub li a {
    display:block;
    width:110px;
    height:120px;
    float:left;
    overflow:hidden;
    position:relative;
    text-decoration:none;
    color:#000;
}
ul.sub li a b {
    font-weight:700;
    display:block;
    padding:15px 15px 5px;
}
ul.sub li a p {
    font-size:12px;
    display:block;
    margin:0;
    padding:0 10px;
}
ul.sub li a i {
    display:block;
    width:64px;
    height:64px;
    position:absolute;
    right:10px;
    bottom:10px;
    background:url(../images/post.png);
    opacity:0.1;
    filter:alpha(opacity = 10);
    -webkit-transition-duration:.5s;
    -moz-transition-duration:.5s;
    -o-transition-duration:.5s;
}
ul.nav > li:hover {
    width:600px;
}
ul.nav > li a.ie6:hover {
    direction:ltr;
    width:600px;
}
ul.sub li a:hover i {
    opacity:1.0;
}

/* demo page styles */
body {
    background:#eee;
    margin:0;
    padding:0;
    font-family: "Trebuchet MS",Arial,Helvetica,sans-serif;
}
.example {
    position:relative;
    background:#fff url(../images/background.jpg);
    width:650px;
    height:382px;
    border:1px #000 solid;
    margin:20px auto;
    border-radius:3px;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
}
/* main menu styles */
ul.nav {
    list-style:none;
    height:120px;
    margin:0;
    padding:0;
}
ul.nav table {
    border-collapse:collapse;
    width:0;
    height:0;
    margin:-1px 0 -5px -1px;
}
ul.nav > li {
    float:right;
    height:120px;
    width:40px;
    position:relative;
    overflow:hidden;
    -webkit-transition-duration:.5s;
    -moz-transition-duration:.5s;
    -o-transition-duration:.5s;
}
* html ul.nav > li {
    width:auto;
}
ul.nav > li a.ie6 {
    float:left;
    height:120px;
    width:39px;
    position:relative;
    overflow:hidden;
}
ul.sub {
    list-style:none;
    height:120px;
    width:600px;
    background:url(../images/panel.png) no-repeat right top;
    position:absolute;
    left:0;
    top:0;
    margin:0;
    padding:0;
}
ul.sub li {
    float:left;
}
ul.sub li:first-child {
    margin-left:45px;
}
ul.sub li a {
    display:block;
    width:110px;
    height:120px;
    float:left;
    overflow:hidden;
    position:relative;
    text-decoration:none;
    color:#000;
}
ul.sub li a b {
    font-weight:700;
    display:block;
    padding:15px 15px 5px;
}
ul.sub li a p {
    font-size:12px;
    display:block;
    margin:0;
    padding:0 10px;
}
ul.sub li a i {
    display:block;
    width:64px;
    height:64px;
    position:absolute;
    right:10px;
    bottom:10px;
    background:url(../images/post.png);
    opacity:0.1;
    filter:alpha(opacity = 10);
    -webkit-transition-duration:.5s;
    -moz-transition-duration:.5s;
    -o-transition-duration:.5s;
}
ul.nav > li:hover {
    width:600px;
}
ul.nav > li a.ie6:hover {
    direction:ltr;
    width:600px;
}
ul.sub li a:hover i {
    opacity:1.0;
}

步骤3.图片 (Step 3. Images)

Here are three images for our menu:

这是菜单的三张图片:

post icon
发布图标
slideout panel
滑出面板
page background
页面背景
现场演示

结论 (Conclusion)

Today we made new nice menu (fifth), your comments and thanks are very welcomed. Good luck!

今天我们做了新的漂亮的菜单(第五),非常欢迎您的评论和感谢。 祝好运!

翻译自: https://www.script-tutorials.com/creating-css3-slideout-menu-5/

css菜单上滑的效果

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>网页特效|Linkweb.cn/Js|---滑出菜单</title> <style> <!-- #ssm2 A { color:black; text-decoration:none; font-size:12; font-family:verdana; } #ssm2 A:hover { color:red; } --> </style> </head> <body> <script language="JavaScript"> function MM_displayStatusMsg(msgStr) { status=msgStr; document.MM_returnValue = true; } function highlight(x){ document.forms[x].elements[0].focus() document.forms[x].elements[0].select() } function MM_jumpMenu(targ,selObj,restore){ eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } var NS IE=document.all; NS=document.layers; hdrFontFamily="Verdana"; hdrFontSize="2"; hdrFontColor="white"; hdrBGColor="#666666"; linkFontFamily="Verdana"; linkFontSize="2"; linkBGColor="white"; linkOverBGColor="#CCCCCC"; linkTarget="_top"; YOffset=60; staticYOffset=20; menuBGColor="black"; menuIsStatic="no"; menuHeader="大类菜单1" menuWidth=150; // Must be a multiple of 5! staticMode="advanced" barBGColor="#1298fd"; barFontFamily="Verdana"; barFontSize="2"; barFontColor="white"; barText="滑出菜单"; function moveOut() { if (window.cancel) { cancel=""; } if (window.moving2) { clearTimeout(moving2); moving2=""; } if ((IE && ssm2.style.pixelLeft<0)||(NS && document.ssm2.left<0)) { if (IE) {ssm2.style.pixelLeft += (5%menuWidth); } if (NS) { document.ssm2.left += (5%menuWidth); } moving1 = setTimeout('moveOut()', 5) } else { clearTimeout(moving1) } }; function moveBack() { cancel = moveBack1() } function moveBack1() { if (window.moving1) { clearTimeout(moving1) } if ((IE && ssm2.style.pixelLeft>(-menuWidth))||(NS && document.ssm2.left>(-150))) { if (IE) {ssm2.style.pixelLeft -= (5%menuWidth); } if (NS) { document.ssm2.left -= (5%menuWidth); } moving2 = setTimeout('moveBack1()', 5)} else { clearTimeout(moving2) } }; lastY = 0; function makeStatic(mode) { if (IE) {winY = document.body.scrollTop;var NM=ssm2.style } if (NS) {winY = window.pageYOffset;var NM=document.ssm2 } if (mode=="smooth") { if ((IE||NS) && winY!=lastY) { smooth = .2 * (winY - lastY); if(smooth > 0) smooth = Math.ceil(smooth); else smooth = Math.floor(smooth); if (IE) NM.pixelTop+=smooth; if (NS) NM.top+=smooth; lastY = lastY+smooth; } setTimeout('makeStatic("smooth")', 1) } else if (mode=="advanced") { if ((IE||NS) && winY>YOffset-staticYOffset) { if (IE) {NM.pixelTop=winY+staticYOffset } if (NS) {NM.top=winY+staticYOffset } } else { if (IE) {NM.pixelTop=YOffset } if (NS) {NM.top=YOffset-7 } } setTimeout('makeStatic("advanced")', 1) } } function init() { if (IE) { ssm2.style.pixelLeft = -menuWidth; ssm2.style.visibility = "visible" } else if (NS) { document.ssm2.left = -menuWidth; document.ssm2.visibility = "show" } else { alert('Choose either the "smooth" or "advanced" static modes!') } } function MM_displayStatusMsg(msgStr) { status=msgStr; document.MM_returnValue = true; } </script> <script language="JavaScript"> if (IE) {document.write('<DIV ID="ssm2" style="visibility:hidden;Position : Absolute ;Left : 0px ;Top : '+YOffset+'px ;Z-Index : 20;width:1px" onmouseover="moveOut()" onmouseout="moveBack()">')} if (NS) {document.write('<LAYER visibility="hide" top="'+YOffset+'" name="ssm2" bgcolor="'+menuBGColor+'" left="0" onmouseover="moveOut()" onmouseout="moveBack()">')} tempBar="" for (i=0;i<barText.length;i++) { tempBar+=barText.substring(i, i+1)+"<BR>"} document.write('<table border="0" cellpadding="0" cellspacing="1" width="'+(menuWidth+16+2)+'" bgcolor="'+menuBGColor+'"><tr><td bgcolor="'+hdrBGColor+'" WIDTH="'+menuWidth+'"> <font face="'+hdrFontFamily+'" Size="'+hdrFontSize+'" COLOR="'+hdrFontColor+'"><b>'+menuHeader+'</b></font></td><td align="center" rowspan="100" width="16" bgcolor="'+barBGColor+'"><p align="center"><font face="'+barFontFamily+'" Size="'+barFontSize+'" COLOR="'+barFontColor+'"><B>'+tempBar+'</B></font></p></TD></tr>') function addItem(text, link, target) { if (!target) {target=linkTarget} document.write('<TR><TD BGCOLOR="'+linkBGColor+'" onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'"><ILAYER><LAYER onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'" WIDTH="100%"><FONT face="'+linkFontFamily+'" Size="'+linkFontSize+'"> <A HREF="'+link+'" target="'+target+'" CLASS="ssm2Items">'+text+'</A></FONT></LAYER></ILAYER></TD></TR>')} function addHdr(text) { document.write('<tr><td bgcolor="'+hdrBGColor+'" WIDTH="140"> <font face="'+hdrFontFamily+'" Size="'+hdrFontSize+'" COLOR="'+hdrFontColor+'"><b>'+text+'</b></font></td></tr>')} //Only edit the script between HERE addItem(' 小类菜单1', '#', '_blank'); addItem(' 小类菜单2', '#', '_blank'); addItem(' 小类菜单3', '#', '_blank'); addItem(' 小类菜单4', '#', '_blank'); addItem(' 小类菜单5', '#', '_blank'); addItem(' 小类菜单6', '#', '_blank'); addHdr('大类菜单2'); addItem(' 小类菜单1', '#', '_blank'); addItem(' 小类菜单2', '#', '_blank'); addItem(' 小类菜单3', '#', '_blank'); addItem(' 小类菜单4', '#', '_blank'); addItem(' 小类菜单5', '#', '_blank'); addItem(' 小类菜单6', '#', '_blank'); // and HERE! No more! document.write('<tr><td bgcolor="'+hdrBGColor+'"><font size="0" face="Arial"> </font></td></TR></table>') if (IE) {document.write('</DIV>')} if (NS) {document.write('</LAYER>')} if ((IE||NS) && (menuIsStatic=="yes"&&staticMode)) {makeStatic(staticMode);} </script> <script> window.onload=init </script> </body> </html>
使用js,当鼠标动,滑出隐藏菜单 //通过参数获取class或者id 对象 var window_width = document.body.scrollWidth; var window_height = document.body.scrollHeight; var g=function(id){ if(id.substr(0,1)=='.') { return document.getElementsByClassName(id.substr(1)); } return document.getElementById(id); } var isShow = false; var showNav= function(left_val){ setTimeout(function a(){ if(left_val < 0){ g("nav").style.left=left_val +"px"; left_val += 5; a(); } },200); } var hiddNav = function(left_val){ setTimeout(function b(){ if(left_val > Math.min(window_width,window_height)/-2){ g("nav").style.left=left_val +"px"; left_val -= 5; b(); // hiddNav(left_val); } },200); } function a(){ g("nav").style.width = Math.min(window_width,window_height)/2 +"px"; g("nav").style.left = Math.min(window_width,window_height)/-2 +"px"; } a(); var glideNav = function (glide){ var nav = function(){ if(!isShow){ // g("nav").className = "nav nav_action"; var left_val = Math.min(window_width,window_height)/-2; showNav(left_val); isShow = true; } } var navHidd = function(){ if(isShow){ // g("nav").className = "nav"; var left_val = 0; hiddNav(left_val); isShow = false; } } if(glide){ nav(); }else{ navHidd(); } }; var obj = { state:{ mouseX:0, mouseY:0 }, move:{ moveX:0, moveY:0 } } document.addEventListener("touchstart",function(e){ e.stopImmediatePropagation(); obj.state.dragable = true; obj.state.mouseX = e.targetTouches[0].pageX; obj.state.mouseY = e.targetTouches[0].pageY; }); document.addEventListener("touchmove", function(e){ e.stopImmediatePropagation(); var x = e.targetTouches[0].pageX - obj.state.mouseX; var y = e.targetTouches[0].pageY - obj.state.mouseY; if(x>10){ glideNav(true); }else if(x<10){ glideNav(false); } }); document.addEventListener("mousedown",function(e){ e.stopImmediatePropagation(); obj.state.dragable = true; obj.state.mouseX = e.screenX; obj.state.mouseY = e.screenY; }); document.addEventListener("mouseup", function(e){ e.stopImmediatePropagation(); var x = e.screenX - obj.state.mouseX; var y = e.screenY - obj.state.mouseY; if(x>10){ glideNav(true); }else if(x<10){ glideNav(false); } });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值