加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

微信小程序之图片处理(居中、铺满屏幕)附源程序

发布时间:2020-12-14 20:27:13 所属栏目:资源 来源:网络整理
导读:图片显示是小程序设计必须要经过的步骤,本人看到网上教学有限,现整理出自己设计过程中出现的问题,应该可以解决你遇到的问题。 用最后给的完整代码,按照我的步骤一定能调试出来,不行再。 先给用到的代码以及效果图: 先给home .wxml 程序: pre class="h

图片显示是小程序设计必须要经过的步骤,本人看到网上教学有限,现整理出自己设计过程中出现的问题,应该可以解决你遇到的问题。

用最后给的完整代码,按照我的步骤一定能调试出来,不行再。

先给用到的代码以及效果图:

先给home.wxml程序:

<pre class="has">
<code class="language-html">

1.图片居中(屏幕顶部):

<pre class="has">
<code class="language-css">//.wxss里的参数
.imagesize{
display:flex; //flex布局
justify-content: center; //水平轴线居中
}
.imagesize image {
width:400rpx;
height:400rpx;
}

<p style="text-indent:50px;">

<img alt="" class="has" height="504" src="https://www.52php.cn/res/2019/01-02/09/89362b2d086815f5f828330dfb63d8d1.jpg" width="707">

<p style="text-indent:50px;">上面设置的图片尺寸,仅仅是为了方便看到实际的效果。

2.图片居中(中部,位置可调 →height 和 align-items)

<pre class="has">
<code class="language-css">.imagesize{
display:flex;
height: 600px; //flex布局高度
justify-content: center;
align-items:center; //垂直居中

}
.imagesize image {
width:400rpx;
height:400rpx;
}

<p style="text-indent:50px;"><img alt="" class="has" height="341" src="https://www.52php.cn/res/2019/01-02/09/7b8bd91e38421b390a6b1e3f9d4ef44a.jpg" width="192"><img alt="" class="has" height="334" src="https://www.52php.cn/res/2019/01-02/09/b713a0a4e47b080063b424b356f15a28.jpg" width="187"><img alt="" class="has" height="335" src="https://www.52php.cn/res/2019/01-02/09/794247881f39e7154dd1961cca514041.jpg" width="190">

<p style="text-indent:50px;">?

上图的height值分别为:?200px ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?400px ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?600px

前两种都不适用全部型号手机,因为手机屏幕尺寸不固定。

但是,对于设计图片位置很有帮助。

3.图片居中(屏幕正中间)

代码:

<pre class="has">
<code class="language-css">page{
height:100% //满屏设置
}
.imagesize{
display:flex;
height: 100%; //设置布局满屏
justify-content: center;
align-items:center;

}
.imagesize image {
width:400rpx;
height:400rpx;
}

看效果:

完整代码(之前的也有完整代码,现给出的加到之前的文件夹下就行):

home.wxml

<pre class="has">
<code class="language-html">

home.wxss

<pre class="has">
<code class="language-css">page{
height:100%
}
.imagesize{
display:flex;
height: 100%;
justify-content: center;
align-items:center;

}
.imagesize image {
width:400rpx;
height:400rpx;
}

5.铺满屏幕:

单独讲铺满屏幕,主要用到mode='widthFix'

具体加在的程序段是.wxml:

<pre class="has">
<code class="language-html">

以及.wxss的改变:

<pre class="has">
<code class="language-css">page{
height:100%
}
.imagesize{
display:flex;
height: 100%;
justify-content: center;
align-items:center;
}

换了一张图做演示:

看看不加widthFix的效果图:

所以还是很有用的。

这里由于是底部tab窗口,所以没有显示完整屏幕覆盖的图。

可以设计启动画面,当然截取合适比例的图会影响实际显示效果,还有就是背景颜色与图片颜色的不同需要你调试时候注意一下。

转载请联系:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读