js展开菜单效果(一)
2016-09-11 16:08
99 查看
前言:
废话不多说了,内容很简单。一个是点击展开效果,一个是展示广告然后定时关闭效果。后续写一个JD的二级菜单展示。
总结:
在定时效果中,实际上用动画会好得多,这种方法吃力不讨好,而且return语句是不能少的。
另外,用JQ或者CSS3都会非常简单。知识储备还是得越丰富越好。
废话不多说了,内容很简单。一个是点击展开效果,一个是展示广告然后定时关闭效果。后续写一个JD的二级菜单展示。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset = UTF-8> <title>test</title> <script> </script> <style type="text/css" rel = "stylesheet"> body{ margin:0; padding:0; } h1,h2{ margin: 0; padding: 0; } /* 展开次级选项 #main-page{ width: 300px; margin:0 auto; border:1px solid #8f8f8f; } #hide-page{ display: none; } #wrap{ margin: 0; text-align: center; } #wrap a:link{ font-size: 1rem; color:#fff; background-color: #8f8f8f; text-decoration: none; padding:1px; } #wrap a:hover{ background-color: blue; }*/ /***************************************/ /*定时展开收起sina首页 #main-page{ width: 300px; margin: 0 auto; background-color: #8f8f8f; text-align: center; overflow: hidden; } #ad{ width: 300px; padding: 5px 0; text-align: center; background-color: #e8e8e8; margin: 0 auto; }*/ </style> <script type="text/javascript"> //展开次级选项 // window.onload = function(){ // var isShow = false; // var btn = document.getElementById("btn"); // var hidePage = document.getElementById("hide-page"); // btn.onclick = function(){ // if(isShow == false){ // btn.innerHTML = "收起选项"; // hidePage.style.display = "block"; // isShow = true; // } // else{ // btn.innerHTML = "更多选项"; // hidePage.style.display = "none"; // isShow = false; // } // } // } /************************************************************************************/ //定时展开收起sina首页,这里return语句不可少,否则形成无限循环,达不到效果。 // window.onload = function(){ // var ad = document.getElementById("ad"); // var mainPage = document.getElementById("main-page"); // var h = 0; // function increaseHeight(){ // if(h < 300){ // mainPage.style.height = h + "px"; // h += 5; // } // else{ // return; // } // setTimeout(increaseHeight,10); // } // function decreaseHeight(){ // if(h > 0){ // h -= 5; // mainPage.style.height = h + "px"; // } // else{ // return; // } // setTimeout(decreaseHeight,10); // } // increaseHeight(); // setTimeout(decreaseHeight,5000); // } </script> </head> <body> <!-- <div id = "main-page"> <p>手机-精选</p> <p>网络:移动4G 联通3G</p> <div id = "hide-page"> <p>价格:5000以上</p> <p>特点:JDphone价格 "0"元购机计划</p> </div> </div> <p id="wrap"> <a id="btn" href = "javascript:">更多选项</a> </p> --> <div id = "main-page"> <h1>欢迎光临</h1> <h2>广告部分</h2> </div> <div id = "ad">广告</div> </body> </html>
总结:
在定时效果中,实际上用动画会好得多,这种方法吃力不讨好,而且return语句是不能少的。
另外,用JQ或者CSS3都会非常简单。知识储备还是得越丰富越好。
相关文章推荐
- 实用js+css多级树形展开效果导航菜单
- JS+CSS实现的简单折叠展开多级菜单效果
- JS实现鼠标滑过折叠与展开菜单效果代码
- js实现可折叠展开的手风琴菜单效果
- JS实现光滑展开合拢的菜单效果代码
- js实现可折叠展开的手风琴菜单效果
- JS+CSS实现的简单折叠展开多级菜单效果
- JS实现光滑展开合拢的菜单效果代码
- JS实现鼠标滑过折叠与展开菜单效果代码
- Flash效果的网站后台左侧Js多级展开菜单代码
- jQuery 导航菜单点击伸缩展开效果的JS特效
- js+css多级树形展开效果导航菜单
- 效果直逼flash的Div+Css+Js菜单
- JS后台菜单效果,可刷新保持
- [原创 js] 点击展开关闭效果
- mm_menu.js(实现鼠标移入横向显示二级菜单效果)(2)
- mm_menu.js(实现鼠标移入横向显示二级菜单效果)(1)
- 一多层展开菜单JS
- 一个简单的JS菜单,带效果截图
- 转载(效果直逼flash的Div+Css+Js菜单)