首頁  >  文章  >  微信小程式  >  小程式開發DEMO實例

小程式開發DEMO實例

Y2J
Y2J原創
2017-05-11 13:22:202373瀏覽

微信小程式佈局實例:

以下將會依照以下的順序介紹:

佈局的實作
邏輯的實作
樣式的實作

1.佈局的實現

最大的佈局是view,view佈局中包含了:一張圖片,文字描述,資訊列和分界線

<!--最外层-->
<view class="home-view1">
  <!--图片层-->
  <view class="home-view2">
    <image class="home-image1" src="http://qty83k.creatby.com/materials/origin/640e31829b8776967dedc670b5427d0f_origin.jpg"></image>
  </view>
  
  <!--描述层-->
  <text class="home-text1">小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物</text>
  
  <!--信息层-->
  <view class="home-view3">
    <view class="home-view4" >
      <image class="home-image-heart" src="http://qty83k.creatby.com/materials/origin/c5656ef00d38d89eae437c5a9102f8fa_origin.png"></image>
  
      <text class="home-text-heart bgColor" > 22</text>
    </view>
    <text class="home-text-time" >2016.10.29</text>
  </view>
  
  <!--分界线line-->
  <view class="home-view-line"></view>
  
  <!--图片层(下面的代码直接复制了上面的所有布局代码)-->
  <view class="home-view2">
    <image class="home-image1" src="http://qty83k.creatby.com/materials/origin/640e31829b8776967dedc670b5427d0f_origin.jpg"></image>
  </view>
  
  <!--描述层-->
  <text class="home-text1">小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物小巧可爱的案头雅物</text>
  
  <!--信息层-->
  <view class="home-view3">
    <view class="home-view4" >
      <image class="home-image-heart" src="http://qty83k.creatby.com/materials/origin/c5656ef00d38d89eae437c5a9102f8fa_origin.png"></image>
  
      <text class="home-text-heart bgColor" > 22</text>
    </view>
    <text class="home-text-time" >2016.10.29</text>
  </view>
  
  <!--分界线line-->
  <view class="home-view-line"></view>
  
</view>

2 .邏輯的實作

只是註冊了Page介面

Page({
  
  data:{
  
  }
  
})

3.樣式的實作

.home-view1樣式:display規定最大View佈局為彈性佈局,justify-content規定內容居中,垂直排列, …

.home-view3樣式:display規定了資訊欄佈局為彈性佈局,justify-content規定內容等級平均分配

.home-view4樣式:display規定了收藏圖片和收藏數的父親佈局為彈性佈局,align-items規定內容在垂直方向居中

.home- image1樣式:規定圖片的高度

.home-image-heart樣式:規定收藏圖片的大小

.home-text1樣式:規定描述文字的樣式,text-align 規定文字居中,line-height規定兩行文字之間的高度

.home-text-heart樣式:規定收藏數的樣式,border-radius規定邊界圓角

.home-view-line樣式:是一條分界線

.bgColor樣式:規定收藏數的背景

.home-view1{
  display: flex;
  justify-content: center;
  flex-direction: column;
  
  height: 100%;
  width: 100%;
  margin: 6px;
  
}
  
.home-view3{
  display: flex;
  justify-content: space-between;
}
  
.home-view4{
  display: flex;
  align-items: center;
}
  
.home-image1{
  height: 200px;
}
  
.home-image-heart{
  width: 30px;
  height: 30px;
}
  
.home-text1{
  text-align: left;
  line-height: 25px;
  margin-top: 6px;
  margin-right: 6px;
  color: gray;
}
  
.home-text-heart{
  width: 22px;
  height: 22px;
  margin-left: 10px;
  border-radius: 20%;
  pad: 5px;
  text-align: center;
}
  
.home-text-time{
  text-align: center;
  margin-right: 20px;
  padding-top: 5px;
  color: gray;
}
  
.home-view-line{
  
 width: 100%;
 height: 6px;
 margin-top: 5px;
 background-color: gainsboro;
}
  
.bgColor{
  background-color: lightblue;
  opacity: 0.6;
}

 【相關推薦】

1. 微信小程式完整原始碼下載

#2. 微信小程式學習用demo:聊天室+音視訊+新增內容

以上是小程式開發DEMO實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn