Vue 封装可向左向右查看图片列表的组件
实现了图片列表展示的功能,一次性可查看4张图,可向左向右点击查看,代码如下:
index.vue:
<template>
<div class="content-container">
<div class="content-container-item content">
<!-- 使用transition加过渡效果 -->
<transition-group tag="div" class="content-inner" name="list" mode="out-in">
<!-- 图片列表封装成组件,以便扩展 -->
<pic-list v-for="item in showPicList" :key="item.code" :picItem="item.picList"></pic-list>
</transition-group>
</div>
<!-- 向左点击查看图片按钮 -->
<div class="content-container-item icon-container left-icon-container">
<div @click="prevStation" class="shuffling-btn prev"></div>
</div>
<!-- 向右点击查看图片按钮 -->
<div class="content-container-item icon-container right-icon-container">
<div @click="nextStation" class="shuffling-btn next"></div>
</div>
</div>
</template> <script>
import picList from './pic-list';
export default {
name: 'pictureContainer',
data() {
return {
showPicList: [{
code: 1,
picList: './1.jpg'
},
{
code: 2,
picList: './2.jpg'
},
{
code: 3,
picList: './3.jpg'
},
{
code: 4,
picList: './4.jpg'
},
{
code: 5,
picList: './5.jpg'
},
{
code: 6,
picList: './6.jpg'
},
{
code: 7,
picList: './7.jpg'
},
{
code: 8,
picList: './8.jpg'
}],
watchList: [], //图片列表list
showListIndex: 0, //当前页面显示的第一个图片列表在watchList中的位置
}
},
components: {
picList
},
mounted() {
//加载图片列表
this.getWatchList();
},
methods: {
/**
* @description 获取可视范围图片列表
*/
getWatchList() {
this.watchList = this.showPicList;
if(this.watchList.length <= 4) {
this.showPicList = this.watchList;
} else {
this.showPicList = this.watchList.slice(0, 4);
}
},
/**
* @description 向右点击事件
*/
nextStation() {
if((this.showListIndex + 4) < this.watchList.length) {
this.showPicList = this.watchList.slice(++this.showListIndex, this.showListIndex + 4);
} else {
utils.showAlert('右侧已无数据');
}
},
/**
* @description 向左点击事件
*/
prevStation() {
if(this.showListIndex > 0) {
this.showPicList = this.watchList.slice(--this.showListIndex, this.showListIndex + 4);
} else {
utils.showAlert('左侧已无数据');
}
}
}
}
</script> <style scoped lang="less">
@icon-container-width: .3rem;
@title-background: #35393E; .content-container {
width: 100%;
height: 1.3rem;
background: @title-background;
.icon-container {
width: @icon-container-width;
max-width: @icon-container-width;
}
.left-icon-container {
margin-left: -100%;
}
.right-icon-container {
margin-left: @icon-container-width;
&:after {
display: block;
content: '';
clear: both;
height: 0;
line-height: 0;
visibility: hidden;
}
}
.content-container-item {
float: left;
height: 100%;
position: relative;
.shuffling-btn {
position: absolute;
top: 50%;
left: 50%;
margin-left: -.25rem;
margin-top: -.25rem;
cursor: pointer;
width: .5rem;
height: .5rem;
border-radius: .5rem;
}
.prev {
background: url(./prev.png) no-repeat;
}
.next {
background: url(./next.png) no-repeat;
}
}
.content {
width: 100%;
}
.content-inner {
margin: 0 @icon-container-width;
display: flex;
flex-wrap: nowrap;
align-items: center;
height: 100%;
justify-content: center;
.list-enter-active, .list-leave-active {
transition: opacity 2s ease-in-out;
}
.list-leave, .list-enter {
opacity: 0;
}
}
}
</style>
子组件 pic-list.vue:
<template>
<div class="main" @click.stop="clickItem(item)">
<div :style="{backgroundImage: 'url(' + item + ')'}"></div>
</div>
</template> <script type="text/ecmascript-6">
/**
* @description 图片列表切换子组件,传递单个item即可
*/ export default {
name: 'picList',
props: {
item: {
type: Object,
default: () => ({})
}
},
methods: {
/**
* @description 点击图片列表事件
*/
clickItem(item) {
this.$emit('showPicture', item);
}
}
}
</script> <style scoped lang="less">
@base-line-height: .4rem;
@item-background-color: #303438; .main {
margin: 2% .1rem;
width: 25%;
min-width: 1rem;
height: 1rem;
color: @item-background-color; &>div {
width: 100%;
height: 100%;
background-size: 100%;
background-repeat: no-repeat;
}
}
</style>
Vue 封装可向左向右查看图片列表的组件的更多相关文章
- 封装实现UIButton左文字右图片
#import "TitleButton.h" @implementation TitleButton - (instancetype)initWithFrame:(CGRect) ...
- js实现图片加载特效(从左到右,百叶窗,从中间到两边)
/* 网上百度的,感觉”从中间到两边“的效果写的不是很好,改了一下,感觉可以了!*/<html> <head> <title></title> < ...
- vue封装一个简单的div框选时间的组件
记录一下我前段时间封装的一个vue组件吧.技术需要积累,有时间我把我之前写的还不错的组件都开源出来.并尝试vue和react 两种方式的组件封装.今天简单写下鼠标框选div选中效果的封装吧. div框 ...
- css3动画 一行字鼠标触发 hover 从左到右颜色渐变
偶然的机会发现的这个东东 这几天做公司的官网 老板突然说出了一个外国网站 我就顺手搜了 并没有发现他说的高科技 但是一个东西深深地吸引了我 就是我下面要说的动画 这个好像不能放视频 我就简单的描述一 ...
- centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标前所有字符 Ctrl+r 搜索命 hash命令 Ctrl+左箭头/右箭头 cd命令 第三节课
centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标 ...
- Vue 监听鼠标左键 鼠标右键以及鼠标中键修饰符click.left&contextmenu&click.middle
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【代码笔记】iOS-可以向左(右)滑动
一,效果图. 二,代码. RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional se ...
- c++ 左值右值 函数模板
1.先看一段代码,这就是一种函数模板的用法,但是红色的部分如果把a写成a++或者写成一个常量比如1,都是编译不过的,因为如果是a++的话,实际上首先是取得a的 值0,而0作为一个常量没有地址.写成1也 ...
- 剑指offer系列——二维数组中,每行从左到右递增,每列从上到下递增,设计算法找其中的一个数
题目:二维数组中,每行从左到右递增,每列从上到下递增,设计一个算法,找其中的一个数 分析: 二维数组这里把它看作一个矩形结构,如图所示: 1 2 8 2 4 9 12 4 7 10 13 6 8 11 ...
随机推荐
- python 面试题1
1.大数据的文件读取 ① 利用生成器generator ②迭代器进行迭代遍历:for line in file 2.迭代器和生成器的区别 1)迭代器是一个更抽象的概念,任何对象,如果它的类有next方 ...
- SQLI DUMB SERIES-21
Cookie Injection- Error Based- complex - string ( 基于错误的复杂的字符型Cookie注入) (1)登录成功后有以下页面: 其中红圈内的字符为admin ...
- Go爬去以太坊的价格数据
package main import ( "encoding/json" "errors" "fmt" "io/ioutil&q ...
- echart 百度地图实现效果
1 必须引入 echarts.js文件 以及 china.js 点文件才可以执行代码2 ehcart官方文档有点小恶心,看了半天,好多东西都不是很清楚,必须挨个实验才行,希望对一些初学者来说可以少走一 ...
- GitHub Desktop下载及使用
GitHub Desktop下载及使用 用了几次 GitHub Desktop 之后,发现不好用,其图形化界面功能有限.推荐使用Git for Windows,官方网站 https://git-f ...
- Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [33,755] milliseconds.
刚部署好程序,第一次登录时,加载非常得慢,查看log日志发现:Creation of SecureRandom instance for session ID generation using [SH ...
- Python练习七
1.写函数,检查传入字典的每一个value的长度,如果大于2,那么仅保留前两个长度的内容,并将新内容返回给调用者. def func(dic): for k in dic: if len(dic[k] ...
- 关于定时器setTimeout()方法的实践--巧解bug
_使用开发环境:UAP:_ _框架:JQuery.MX:_ 最近的开发的页面中,有一处需要在提交的 datagrid里启用行编辑,就会发生奇怪的bug,编辑过程中如图所示不移开焦点直接点保存,那么已输 ...
- jquery 蔚蓝网
$(document).ready(function(){ //提交表单 $("#registerBtn").click(function(){ var email=documen ...
- IO文件流
定义:流是一种抽象的概念,通过流的方式组成无结构字符和字符序列,从流中取数据的操作进行输入输出.[io流的作用就是用流的方式进行输入输出] 常用语法: 1. 首先引用using.system.io ...