vuejs、微信小程序窗帘效果

说明
  • 本程序分为vuejs和微信小程序部分,主要不同会在下面标志出来
  • 代码只是测试用,有不好的地方请见谅
实现思路

实现思路其实很简单,就是根据获取的宽度值修改div层的宽度

效果图
vuejs部分

前端代码部分--相信大家一看就明白

  • 主要部分在:style="{width:imgWidth+'%'}"这里
<div class="main-chuanglian"
             @touchmove.prevent="mouseMoving"
             @touchend.stop="stopDrag">
          <div class="chuanlian-bar">
          <span class="chuanglian-num" :style="tempElementStyle(el)" v-for="el in temperatureGrades" :key="el">
            <label class="chuanglian-text">{{el}}</label>
          </span>
            <div class="chuanglian-sel-block" :style="sliderStyle">
              <div class="chuanglian-sel-bar"  @touchstart.stop="startDrag">

              </div>
            </div>
          </div>

          <div style="position: relative;top:10px;width: 220px">
            <div class="leftcurtain">
              <img src="./../assets/frontcurtain.jpg" style="height: 100%;position: absolute;left: 0" :style="{width:imgWidth+'%'}"/>
            </div>
            <div class="rightcurtain">
              <img src="./../assets/frontcurtain.jpg" style="height:100%;position: absolute;right: 0" :style="{width:imgWidth+'%'}"/>
            </div>
          </div>
</div>

js代码部分

代码请参考文章“vuejs刻度尺代码,通过移动标志块进行调整刻度的方式”的js代码部分
微信小程序部分

前端代码部分--相信大家一看就明白
主要部分在width:{{currentTemperature | round}}%这里

<view>
          <view class="main-chuanglian"
          bindtouchmove="mouseMoving"
          bindtouchend="stopDrag">
            <view class="chuanlian-bar">
              <span class="chuanglian-num" style="{{tempElementStyle(el)}}" wx:for="{{temperatureGrades}}" wx:key="{{item}}">
                <label class="chuanglian-text">{{item}}</label>
              </span>
              <view class="chuanglian-sel-block" style="{{sliderStyle}}">
                <view class="chuanglian-sel-bar"  bindtouchstart="startDrag" bindtouchmove="mouseMoving">

                </view>
              </view>
            </view>

            <view style="position: relative;top:15px;width: 220px">
              <view class="leftcurtain">
                <image src="../../res/img/frontcurtain.jpg" 
                style="height: 100%;position: absolute;left: 0;width:{{currentTemperature | round}}%"></image>
              </view>
              <view class="rightcurtain">
                <image src="../../res/img/frontcurtain.jpg" 
                style="height:100%;position: absolute;right: 0;width:{{currentTemperature | round}}%"></image>
</view>

js代码部分

代码请参考文章“小程序刻度尺代码,通过移动标志块进行调整刻度的方式”的js代码部分

因为是测试代码,css样式就用的是同一套啦

.main-chuanglian{
  background: #dddddd;
  width: 220px;
  margin:30px auto;
  position: absolute;
  right:10px;
  top:15%;
}
.chuanlian-bar{
  height:15px;
  line-height:15px;
  position: relative;
}
.chuanglian-num{
  display: inline-block;
  background: #eeeeee;
  text-align: center;
  width:44px;
}
.chuanglian-text{
  font-size:10px;
  color:#bbbbbb;
}
.chuanglian-sel-block{
  width: 25px;
  height: 20px;
  margin-top: 0px;
  position: relative;
  top:-20px;
}
.chuanglian-sel-bar{
  position: absolute;
  height:25px;
  width:25px;
  border-radius: 25px;
  background: #bbbbbb;
  top:-2px;
  left:15%;
  border:1px solid #dddddd;
}
.leftcurtain{
  width:50%;
  height:205px;
  top:0px;
  left:0px;
  position:absolute;
  z-index:2;
}
.rightcurtain{
  width:50%;
  height:205px;
  right:0px;
  top:0px;
  position:absolute;
  z-index:3;
}
总结
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,262评论 25 709
  • 我妈妈的头发染成了棕色的。妈妈瘦瘦的,腿长长的。妈妈的眉毛弯弯的,黑黑的。眼睛大大的,鼻梁挺挺的,耳朵被头发遮...
    豪达兄弟阅读 3,097评论 3 1
  • 有的人走的时候,静静的,谁也不知道,就像每个故事的最初,谁也不知晓谁,然后就没再见到。 (我大概有四个月没有写日志...
    开明开明开明阅读 3,919评论 0 0
  • 淡雲孤鴻: 认为自己是一个天生的歌唱家的蝉,整个夏天都在歌唱中度过。 时间在不知不觉中向前推移,慢慢地进入北风...
    lilys阅读 1,813评论 0 1
  • 何时降临一场倾盆大雨 将这积满灰尘的世界清洗 还它们最本真的面貌 何处借个肩膀好好哭一回 用泪水洗涤双眼 把所有伤...
    清语倾城阅读 2,635评论 3 7