小程序开发 各种Demo的记录博客
前言
学习小程序的Demo记录博客
微信小程序开放文档 https://developers.weixin.qq.com/miniprogram/dev/framework/
css文档 https://developer.mozilla.org/zh-CN/docs/Web/CSS/border-radius
横向排列Demo
效果图
viewdemo.wxml
<view class="demoview"> <view>1view> <view>2view> <view>3view> view>
viewdemo.wxss
/* pages/demo/demo.wxss */ .demoview view{ width: 100px; height: 100px; /* 文字排列 */ text-align:center; /* 行高 */ line-height: 100px; } /* 指定某个child view的风格 */ .demoview view:nth-child(1){ background-color: lightskyblue; } .demoview view:nth-child(2){ background-color:lightgreen; } .demoview view:nth-child(3){ background-color:lightsalmon; } .demoview{ /* 排列方式 */ display:flex; /* 排列的时候的间距 元素中的各项周围留有空白*/ justify-content: space-around; }
纵向与横向滚动Demo
效果图
scrollview.wxml
<view> <scroll-view class="scrollview" scroll-y> <view>Aview> <view>Bview> <view>Cview> <view>Dview> <view>Eview> <view>Fview> <view>Gview> scroll-view> <scroll-view class="scrollview2" scroll-x> <view>1view> <view>2view> <view>3view> <view>4view> <view>5view> <view>6view> <view>7view> scroll-view> view>
scrollview.wxss
/* pages/scrollview/scrollview.wxss */ /* ==================纵向=================== */ .scrollview view{ width: 100%; height: 30%; /* 文字排列 */ text-align: center; line-height: 100px; background-color: white; } .scrollview :nth-child(1){ /* 背景颜色 */ background-color: lightsalmon; } .scrollview :nth-child(2){ background-color: lightgreen; } .scrollview :nth-child(3){ background-color: lightskyblue; } .scrollview :nth-child(4){ /* 背景颜色 */ background-color: lightgoldenrodyellow; } .scrollview{ background-color: wheat; /* 红色边框线 */ border: 1px solid red; /* 纵向滚动必须给与高度 */ height: 250px; width: 100%; } /* ===================横向=================== */ .scrollview2 view{ width: 30%; height: 100%; /* 文字排列 */ text-align: center; line-height: 300px; background-color: white; /* 子view设置一行 */ display: inline-block } .scrollview2 :nth-child(1){ /* 背景颜色 */ background-color: lightsalmon; } .scrollview2 :nth-child(2){ background-color: lightgreen; } .scrollview2 :nth-child(3){ background-color: lightskyblue; } .scrollview2 :nth-child(4){ /* 背景颜色 */ background-color: lightgoldenrodyellow; } .scrollview2{ background-color: wheat; border: 1px solid red; height: 250px; width: 100%; /* 不换行,单行显示 */ white-space: nowrap; /* 排列方向设置 宫格 */ display: flex; /* 排列方式设置为 一行 */ flex-direction:row; }
图片轮播Demo
效果图
swiper.wxml
<swiper class="swiper-container" indicator-dots indicator-color="white" indicator-active-color="gray" autoplay="true" interval="1000" circular="true"> <swiper-item> <View class="item">AView> swiper-item> <swiper-item> <View class="item">BView> swiper-item> <swiper-item> <View class="item">CView> swiper-item> swiper>
swiper.wxss
/* pages/swiper/swiper.wxss */ .swiper-container { height: 150px; } .item { height: 100%; line-height: 150px; text-align: center; } /* 请注意 下面的swiper-item 前面没有.点 并且 .item前面要加空格*/ swiper-item:nth-child(1) .item { background-color: lightpink; } swiper-item:nth-child(2) .item { background-color: lightseagreen; } swiper-item:nth-child(3) .item { background-color: lightblue; }
Button 按键Demo
效果图
button.wxml
<button>按钮Abutton> <button type="primary">主题色按钮button> <button type="warn">警告按钮button> <button size="mini" style=" margin-top: 100px;">小尺寸按钮button> <view> <button type="primary" size="mini" style="margin-top: 10%;">小尺寸按钮button> view> <button size="mini" plain>镂空按钮button> <button type="primary" size="mini" plain>镂空按钮button> <button type="warn" size="default" plain>镂空按钮button> <button class="buttomstyle">自定义颜色按钮button>
button.wxss
/* pages/button/button.wxss */ .buttomstyle{ background-color:thistle; color: slategray; text-align: center; padding: 0px; margin: 0px; /* 圆角 */ border-radius: 20%; }
Image 图片Demo
效果图
图片存放位置与代码
End