使用H5搭建webapp主页面

使用H5搭建webapp主页面


主页面搭建


思路分析:

Meta标签中的ViewPort属性:ViewPort是承载代码层的一个View视图,而手机浏览器看到网页是承载ViewPort视图。因此,手机看到的层级关系,从上到下:代码View视图->ViewPort视图->浏览器视图。

所以我们只需要修改ViewPort这一层的属性,比如缩放等,即可对手机进行响应式布局,即安卓的自适应布局。


实现的效果图:(左右拖拽即可实现自动调整大小)



步骤一:搭建工程目录结构



步骤二:在index.html中声明ViewPort,输入meta:vp按下tab键自动生成,规定宽度为手机宽度,缩放比例为1



步骤三:由于每个浏览器的默认边距,默认属性的不同,我们需要全部初始化一遍,达到适应不同浏览器。

编写我们的common.css文件,记得在index.html中导入

[css]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. *,  
  2. ::after,  
  3. ::before{  
  4.   margin0;  
  5.   padding0;  
  6.   /*当用户点击iOS的Safari浏览器中的链接或JavaScript的可点击的元素时,覆盖显示的高亮颜色*/  
  7.   -webkit-tap-highlight-colortransparent;  
  8.   /*设置所有是以边框开始计算宽度  百分比*/  
  9.   -webkit-box-sizing:border-box;  
  10.   box-sizing: border-box;  
  11. }  
  12. body{  
  13.     font-size14px;  
  14.     font-family"Microsoft YaHei","sans-serif";  
  15.     color#333;  
  16. }  
  17. a{  
  18.     color#333;  
  19.     text-decorationnone;  
  20. }  
  21. a:hover{  
  22.     text-decorationnone;  
  23. }  
  24. input{  
  25.     bordernone;  
  26.     outlinenone;  
  27.     /*清除移动端默认的表单样式*/  
  28.     -webkit-appearance:none;  
  29. }  
  30. li{  
  31.     list-stylenone;  
  32. }  


步骤四:编写index.html文件

[html]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. <body>  
  2.     <div class="layout">  
  3.           
  4.     </div>  
  5. </body>  


步骤五:编写index.css,来对这个layout类进行布局

[css]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. .layout{  
  2.     width100%;  
  3.     max-width640px;  
  4.     min-width320px;  
  5.     height1000px;  
  6.     margin0 auto;  
  7.     background#ff0000;  
  8. }  


实现效果图:



轮播图和导航栏的搭建


思路分析:

1、导航栏实现:导航栏使用css的position=fixed和z-index=1000,使它固定在顶部并在网页的最上层,左边的icon和右边登陆按钮使用绝对位置来调整距离左边右边上边的距离,而中间的form表单只要Padding-Left和Padding-Right就可以随屏幕伸缩。

2、自动轮播效果实现:这里使用了jQuery的一个js开源库unslider。

3、十个选项按钮实现:使用一个列表,设置每一个li为块元素,宽度为20%,并且让10个选项左浮动,就可以自动排好两行。


实现的效果图:



导航栏实现

步骤一:编写html文件,将导航栏做成一个盒子,并放置需要的组件,并为它们取好类名,方便css的编写

[html]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. <!--搜索头部-->  
  2. <header class="nav_header">  
  3.     <div class="nav">  
  4.         <a href="#" class="nav_logo"></a>  
  5.         <!-- 小键盘  enter 改变成  搜索 按钮 -->  
  6.         <form action="#">  
  7.             <span class="nav_search_icon"></span>  
  8.             <input type="search" placeholder="搜索关键字"/>  
  9.         </form>  
  10.         <a href="#" class="nav_login">登录</a>  
  11.     </div>  
  12. </header>  


步骤二:编写css文件,将放置的东西设置好宽高,宽用百分比可以自适应,高度则是自己测量

[css]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. /*nav*/  
  2. .nav_header{  
  3.     positionfixed;  
  4.     height40px;  
  5.     width100%;  
  6.     top: 0;  
  7.     left: 0;  
  8.     z-index1000;  
  9. }  
  10. .nav_header> .nav{  
  11.     width100%;  
  12.     height40px;  
  13.     max-width640px;  
  14.     min-width320px;  
  15.     margin0 auto;  
  16.     background:rgba(201,21,35,0.00);  
  17.     positionrelative;  
  18. }  
  19. .nav_header> .nav> .nav_logo{  
  20.     width80px;  
  21.     height30px;  
  22.     positionabsolute;  
  23.     backgroundurl("../img/top_logo.png"no-repeat;  
  24.     background-size80px 20px;  
  25.     top: 10px;  
  26.     left: 0;  
  27. }  
  28. .nav_header> .nav> .nav_login{  
  29.     width50px;  
  30.     height40px;  
  31.     line-height40px;  
  32.     text-aligncenter;  
  33.     positionabsolute;  
  34.     right: 0;  
  35.     top: 0;  
  36.     colorwhite;  
  37.     font-size15px;  
  38. }  
  39. .nav_header> .nav> form{  
  40.     width100%;  
  41.     padding-left85px;  
  42.     padding-right50px;  
  43.     height40px;  
  44. }  
  45. .nav_header> .nav> form> input{  
  46.     width100%;  
  47.     height30px;  
  48.     border-radius: 15px;  
  49.     margin-top5px;  
  50.     padding-left30px;  
  51. }  
  52. .nav_header> .nav >form >.nav_search_icon{  
  53.     height20px;  
  54.     width20px;  
  55.     background:url("../img/top_search.png");  
  56.     background-size20px 20px;  
  57.     positionabsolute;  
  58.     left: 90px;  
  59.     top: 10px;  
  60. }  


自动轮播实现

步骤一:根据官网编写自动轮播html文件

[java]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. <!--轮播图-->  
  2. <div class="banner">  
  3.     <div>  
  4.         <ul>  
  5.             <li><a><img src="img/banner_01.jpg"></a></li>  
  6.             <li><a><img src="img/banner_02.jpg"></a></li>  
  7.             <li><a><img src="img/banner_03.jpg"></a></li>  
  8.             <li><a><img src="img/banner_04.jpg"></a></li>  
  9.             <li><a><img src="img/banner_05.jpg"></a></li>  
  10.         </ul>  
  11.     </div>  
  12. </div>  


步骤二:根据官网导入js文件,需要下载unslider.js,它是基于JQuery.js的,所以需要下载2个,导入到项目中

[java]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1.        <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>  
  2. <script type="text/javascript" src="js/unslider.js"></script>  
  3. <script>  
  4. $(function() {  
  5.     $('.banner').unslider({  
  6.         speed : 500,  
  7.            delay : 3000,  
  8.            nav : true,//是否启动导航图标  
  9.            dots: true,//是否出先圆点点  
  10.            arrows : false,  
  11.            autoplay : true //自动轮播             
  12.     });  
  13. })  
  14. </script>  


步骤三:为了使图片能让我们手动滑动,还需要导入2个JQuery的库,导入之后就能手动滑动了

[html]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. <script type="text/javascript" src="js/jquery.event.move.js"></script>  
  2. <script type="text/javascript" src="js/jquery.event.swipe.js"></script>  


步骤四:为了让图片能刚好100%显示出来,并且实现自动轮播导航圆点,需要在css中加入实现

[css]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. /*banner*/  
  2. .banner ul li a img{  
  3.     width100%;  
  4. }  
  5. .unslider {  
  6.     overflowauto;  
  7.     margin0;  
  8.     padding0;  
  9.     /*Added*/  
  10.     positionrelative;  
  11. }  
  12. .unslider-nav{  
  13.     positionabsolute;  
  14.     width100%;  
  15.     bottom: 2%;  
  16. }  


十个选项按钮实现

步骤一:编写html文件

[html]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. <!--导航栏-->  
  2. <nav class="item">  
  3.     <ul class="clearfix">  
  4.         <li>  
  5.             <a href="#">  
  6.                 <img src="img/nav_01.png" alt=""/>  
  7.                 <p>京东超市</p>  
  8.             </a>  
  9.         </li>  
  10.         <li>  
  11.             <a href="#">  
  12.                 <img src="img/nav_02.png" alt=""/>  
  13.                 <p>全球购</p>  
  14.             </a>  
  15.         </li>  
  16.         <li>  
  17.             <a href="#">  
  18.                 <img src="img/nav_03.png" alt=""/>  
  19.                 <p>服装城</p>  
  20.             </a>  
  21.         </li>  
  22.         <li>  
  23.             <a href="#">  
  24.                 <img src="img/nav_04.png" alt=""/>  
  25.                 <p>京东生鲜</p>  
  26.             </a>  
  27.         </li>  
  28.         <li>  
  29.             <a href="#">  
  30.                 <img src="img/nav_05.png" alt=""/>  
  31.                 <p>京东到家</p>  
  32.             </a>  
  33.         </li>  
  34.         <li>  
  35.             <a href="#">  
  36.                 <img src="img/nav_06.png" alt=""/>  
  37.                 <p>充值中心</p>  
  38.             </a>  
  39.         </li>  
  40.         <li>  
  41.             <a href="#">  
  42.                 <img src="img/nav_07.png" alt=""/>  
  43.                 <p>京东金融</p>  
  44.             </a>  
  45.         </li>  
  46.         <li>  
  47.             <a href="#">  
  48.                 <img src="img/nav_08.png" alt=""/>  
  49.                 <p>领券</p>  
  50.             </a>  
  51.         </li>  
  52.         <li>  
  53.             <a href="#">  
  54.                 <img src="img/nav_09.png" alt=""/>  
  55.                 <p>物流查询</p>  
  56.             </a>  
  57.         </li>  
  58.         <li>  
  59.             <a href="#">  
  60.                 <img src="img/nav_10.png" alt=""/>  
  61.                 <p>我的关注</p>  
  62.             </a>  
  63.         </li>  
  64.     </ul>  
  65. </nav>  


步骤二:编写css文件

[css]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. /*item*/  
  2. .item{  
  3.     width100%;  
  4.     height180px;  
  5.     background#fff;  
  6.     margin-top-4px;  
  7.     border-bottom1px solid #e0e0e0;  
  8. }  
  9. .item> ul{  
  10.     width100%;  
  11. }  
  12. .item> ul> li{  
  13.     width20%;  
  14.     floatleft;  
  15. }  
  16. .item> ul> li> a{  
  17.     width100%;  
  18.     displayblock;  
  19.     padding-top20px;  
  20. }  
  21. .item> ul> li> a> img{  
  22.     width40px;  
  23.     height40px;  
  24.     displayblock;  
  25.     margin0 auto;  
  26. }  
  27. .item> ul> li> a> p{  
  28.     text-aligncenter;  
  29.     color#666;  
  30. }  


商品区块的搭建


思路分析:

1、秒杀模块:可以分为头部的倒计时和内容部分三个li存放三个图,并且右边界为1px。

2、左一大图、右两小图:这里使用模块化开发,在css写好width=50%、左右两边1px的border和左浮动右浮动的类,直接在html创建好后使用即可。左大图采用左浮动,右小图采用右浮动,大小都为50%。

3、左两小图、右一大图:左小图采用左浮动,右大图采用有浮动。


实现的效果图:



准备工作

编写common.css,用于模块化开发,只要在class里面放置需要的类名即可:

[css]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. .fl{  
  2.     floatleft;  
  3. }  
  4. .fr{  
  5.     floatright;  
  6. }  
  7. .m_l10{  
  8.     margin-left10px;  
  9. }  
  10. .m_r10{  
  11.     margin-right10px;  
  12. }  
  13. .m_b10{  
  14.     margin-bottom10px;  
  15. }  
  16. .m_t10{  
  17.     margin-top10px;  
  18. }  
  19. .b_l1{  
  20.     border-left1px solid #e0e0e0;  
  21. }  
  22. .b_r1{  
  23.     border-right1px solid #e0e0e0;  
  24. }  
  25. .b_b1{  
  26.     border-bottom1px solid #e0e0e0;  
  27. }  
  28. .w_50{  
  29.     width50%;  
  30.     displayblock;  
  31. }  
  32. .w_50 >img{  
  33.     width100%;  
  34.     displayblock;  
  35. }  
  36. .clearfix::before,  
  37. .clearfix::after{  
  38.     content"";  
  39.     height0;  
  40.     line-height0;  
  41.     displayblock;  
  42.     visibilityhidden;  
  43.     clearboth;  
  44. }  


秒杀区块、左大图右小图、左小图右大图


步骤一:编写html文件

[html]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. <!--商品-->  
  2. <main class="shopItem">  
  3.     <!--秒杀区块-->  
  4.     <section class="shop_box">  
  5.         <!--头部-->  
  6.         <div class="shop_box_tit no_border">  
  7.             <div class="fl m_l10 sk_l">  
  8.                 <span class="sk_l_icon"></span>  
  9.                 <span class="sk_l_name m_l10">掌上秒杀</span>  
  10.                 <div class="sk_l_time m_l10">  
  11.                     <span>0</span>  
  12.                     <span>0</span>  
  13.                     <span>:</span>  
  14.                     <span>0</span>  
  15.                     <span>0</span>  
  16.                     <span>:</span>  
  17.                     <span>0</span>  
  18.                     <span>0</span>  
  19.                 </div>  
  20.             </div>  
  21.             <div class="fr m_r10"><a href="#">更多></a></div>  
  22.         </div>  
  23.         <!--内容-->  
  24.         <div class="sk_con">  
  25.             <ul class="clearfix">  
  26.                 <li>  
  27.                     <a href="#"><img src="img/detail01.jpg" alt=""/></a>  
  28.                     <p>¥10.00</p>  
  29.                     <p>¥100.00</p>  
  30.                 </li>  
  31.                 <li>  
  32.                     <a href="#"><img src="img/detail02.jpg" alt=""/></a>  
  33.                     <p>¥10.00</p>  
  34.                     <p>¥100.00</p>  
  35.                 </li>  
  36.                 <li>  
  37.                     <a href="#"><img src="img/detail01.jpg" alt=""/></a>  
  38.                     <p>¥10.00</p>  
  39.                     <p>¥100.00</p>  
  40.                 </li>  
  41.             </ul>  
  42.         </div>  
  43.     </section>  
  44.     <!--左大图、右小图-->  
  45.     <section class="shop_box">  
  46.         <!--头部-->  
  47.         <div class="shop_box_tit"><h3>京东超市</h3></div>  
  48.         <!--内容-->  
  49.         <div class="clearfix">  
  50.             <a href="#" class="fl w_50 b_r1"><img src="img/cp1.jpg" alt=""/></a>  
  51.             <a href="#" class="fr w_50 b_b1"><img src="img/cp2.jpg" alt=""/></a>  
  52.             <a href="#" class="fr w_50 "><img src="img/cp3.jpg" alt=""/></a>  
  53.         </div>  
  54.     </section>  
  55.     <!--左小图、右大图-->  
  56.     <section class="shop_box">  
  57.         <!--头部-->  
  58.         <div class="shop_box_tit"><h3>京东超市</h3></div>  
  59.         <!--内容-->  
  60.         <div class="clearfix">  
  61.             <a href="#" class="fr w_50 b_l1"><img src="img/cp4.jpg" alt=""/></a>  
  62.             <a href="#" class="fl w_50 b_b1"><img src="img/cp5.jpg" alt=""/></a>  
  63.             <a href="#" class="fl w_50"><img src="img/cp6.jpg" alt=""/></a>  
  64.         </div>  
  65.     </section>  
  66.     <!--左大图、右小图-->  
  67.     <section class="shop_box">  
  68.         <!--头部-->  
  69.         <div class="shop_box_tit"><h3>京东超市</h3></div>  
  70.         <!--内容-->  
  71.         <!--内容-->  
  72.         <div class="clearfix">  
  73.             <a href="#" class="fl w_50 b_r1"><img src="img/cp1.jpg" alt=""/></a>  
  74.             <a href="#" class="fr w_50 b_b1"><img src="img/cp2.jpg" alt=""/></a>  
  75.             <a href="#" class="fr w_50 "><img src="img/cp3.jpg" alt=""/></a>  
  76.         </div>  
  77.     </section>  
  78. </main>  


步骤二:编写css文件

[css]  view plain  copy 
  在CODE上查看代码片 派生到我的代码片
  1. /*shopItem*/  
  2. .shopItem{  
  3.     padding0 5px;  
  4. }  
  5. .shopItem> .shop_box{  
  6.     width100%;  
  7.     margin-top10px;  
  8.     background#fff;  
  9.     box-shadow: 0 0 1px #e0e0e0;  
  10. }  
  11. .shopItem> .shop_box> .shop_box_tit{  
  12.     width100%;  
  13.     height32px;  
  14.     line-height32px;  
  15.     border-bottom1px solid #e0e0e0;  
  16. }  
  17. .shopItem> .shop_box> .shop_box_tit.no_border{  
  18.     border-bottomnone;  
  19. }  
  20. .shopItem> .shop_box> .shop_box_tit> h3{  
  21.     padding-left18px;  
  22.     font-size15px;  
  23.     color#666;  
  24.     font-weightnormal;  
  25.     positionrelative;  
  26. }  
  27. .shopItem> .shop_box> .shop_box_tit> h3::before{  
  28.     content"";  
  29.     width3px;  
  30.     positionabsolute;  
  31.     top: 10px;  
  32.     left: 10px;  
  33.     height12px;  
  34.     background#d8505c;  
  35. }  
  36. .shop_box_sk{  
  37.       
  38. }  
  39. /*秒殺*/  
  40. .sk_l> .sk_l_icon{  
  41.     backgroundurl("../img/sk_icon.png"no-repeat;  
  42.     background-size16px 20px;  
  43.     floatleft;  
  44.     width16px;  
  45.     height20px;  
  46.     margin-top6px;  
  47. }  
  48. .sk_l> .sk_l_name{  
  49.     font-size15px;  
  50.     color#d8505c;  
  51.     floatleft;  
  52. }  
  53. .sk_l> .sk_l_time{  
  54.     margin-top10px;  
  55.     floatleft;  
  56. }  
  57. .sk_l> .sk_l_time> span{  
  58.     floatleft;  
  59.     width15px;  
  60.     line-height15px;  
  61.     height15px;  
  62.     text-aligncenter;  
  63.     background#333;  
  64.     color#fff;  
  65.     margin-left3px;  
  66. }  
  67. .sk_l> .sk_l_time> span:nth-child(3n){  
  68.     color#333;  
  69.     background#fff;  
  70.     width5px;  
  71. }  
  72. .sk_con> ul{  
  73.     width100%;  
  74.     margin8px 0;  
  75. }  
  76. .sk_con> ul> li{  
  77.     width33.33%;  
  78.     floatleft;  
  79. }  
  80. .sk_con> ul> li> a{  
  81.     displayblock;  
  82.     width100%;  
  83.     margin0 auto;  
  84.     border-right1px solid #e0e0e0;  
  85. }  
  86. .sk_con> ul> li:last-child> a{  
  87.     border-right:0;  
  88. }  
  89. .sk_con> ul> li> a> img{  
  90.     width67%;  
  91.     margin0 auto;  
  92.     displayblock;  
  93. }  
  94. .sk_con> ul> li> p{  
  95.     text-aligncenter;  
  96. }  
  97. .sk_con> ul> li> p:first-of-type{  
  98.     color#d8505c;  
  99. }  
  100. .sk_con> ul> li> p:last-of-type{  
  101.     font-size12px;  
  102.     color#666;  
  103.     text-decoration:line-through;  
  104. }  


源码下载http://download.csdn.net/detail/qq_30379689/9640215


文章来源:http://blog.csdn.net/qq_30379689/article/details/52648978

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值