本文为纵向轮播,横向轮播/动态列表组件请戳----

代码是angular的,稍微改改就可以放入Vue项目里,差别不大哟

以下代码可以根据实际情况自行调整

父组件html

<app-scroll-up [dataObj]="dataObjUp">
<div class="slot-one">
<div [style]="{ height: dataObjUp.height + dataObjUp.unit }" class="inner_item"
*ngFor="let item of dataObjUp.scrollList,index as i">
内容:{{ item }}介绍:我是嵌入的slot{{ i+1 }},相当于vue的slot
</div>
</div>
<div class="slot-two">
<div [style]="{ height: dataObjUp.height + dataObjUp.unit }" class="inner_item">
{{ dataObjUp.scrollList[0] }}嵌入的slot2,这里要放和 slot1里面第一个画面一模一样的东西
</div>
</div>
</app-scroll-up>

父组件ts

dataObjUp = {
time: 50,
minLength: 1,
width:200,
height: 200,
unit: 'px',
scrollList: ['1111','2222','3333','444','555','666']
}

子组件html

<div class="scroll_outermost_up" [style]="{ width: dataObj.width + dataObj.unit, height: dataObj.height + dataObj.unit }"
#outerMost (mouseover)="rollStop('over')" (mouseout)="rollStart(60)">
<div class="outer_box" #outerBox1>
<ng-content select=".slot-one"></ng-content>
</div>
<div class="outer_box" #outerBox2>
<ng-content select=".slot-two"></ng-content>
</div>
</div>

子组件ts


import { Component, ElementRef, OnInit, Input, ViewChild, ViewEncapsulation } from '@angular/core'; @Component({
selector: 'app-scroll-up',
templateUrl: './scroll-up.component.html',
styleUrls: ['./scroll-up.component.less'],
encapsulation: ViewEncapsulation.Emulated,
})
export class ScrollUpComponent implements OnInit { constructor() { } ngOnInit(): void {
} @Input()
public dataObj: any = {
time: 50,
minLength: 1,
width:200,
height: 200,
unit: 'px',
scrollList: ['1111','2222','3333','444','555','666']
} @ViewChild('outerMost', { static: false }) outerMost: ElementRef;
@ViewChild('outerBox1', { static: false }) outerBox1: ElementRef;
@ViewChild('outerBox2', { static: false }) outerBox2: ElementRef; ngAfterViewInit() {
setTimeout(()=>{this.roll(this.dataObj.time)},1000)
}
timer = null
ngOnDestroy() {
if (this.timer) clearInterval(this.timer);
}
roll(t) {
var outerMost = this.outerMost.nativeElement
if (this.dataObj.scrollList.length < this.dataObj.minLength) { return console.log('不需要滚动') }
outerMost.scrollTop = 0;
this.rollStart(t);
}
rollStart(t) {
var outerMost = this.outerMost.nativeElement
var outerBox1 = this.outerBox1.nativeElement
this.rollStop('开始');
this.timer = setInterval(() => {
// 当滚动高度大于列表内容高度时恢复为0
outerMost.scrollTop++;
if (outerBox1.scrollHeight - outerMost.scrollTop === 1) {
outerMost.scrollTop = 0;
outerMost.scrollTop++;
}
if (outerMost.scrollTop >= outerBox1.scrollHeight) {
outerMost.scrollTop = 0;
outerMost.scrollTop++;
}
}, t);
}
rollStop(e) {
console.log(e)
clearInterval(this.timer);
} }

子组件less

.scroll_outermost_up {
overflow: hidden; /* 必须 */
cursor: pointer;
.outer_box {
/deep/.inner_item {
background-color: rgb(235, 210, 243);
}
/deep/.inner_item:nth-child(odd) {
background-color: rgb(179, 223, 248);
}
}
}

VUE Angular通用动态列表组件-亦可为自动轮播组件-01-根据数据量自动纵向滚动,鼠标划入停止滚动的更多相关文章

  1. vue实例之组件开发:图片轮播组件

    一.普通方式: 其中,index是关键. <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  2. vue 专题 vue2.0各大前端移动端ui框架组件展示

    Vue 专题 一个数据驱动的组件,为现代化的 Web 界面而生.具有可扩展的数据绑定机制,原生对象即模型,简洁明了的 API 组件化 UI 构建 多个轻量库搭配使用 请访问链接: https://ww ...

  3. C-Swipe Mobile 一个适用于Vue2.x的移动端轮播组件

    近期在做的一个Vue2项目里需要一个可以滑动的轮播组件,但是又因为现有的传统轮播库功能过于繁琐和笨重.因此自己写了一个针对于Vue2.x的轻型轮播组件. 项目GitHub链接:C-Swipe Mobi ...

  4. Vue.js的动态组件模板

    组件并不总是具有相同的结构.有时需要管理许多不同的状态.异步执行此操作会很有帮助. 实例: 组件模板某些网页中用于多个位置,例如通知,注释和附件.让我们来一起看一下评论,看一下我表达的意思是什么.评论 ...

  5. vue通过extend动态创建全局组件(插件)学习小记

    测试环境:nodejs+webpack,例子是看文章的,注释为自己的理解 创建一个toast.vue文件: <template> <div class="wrap" ...

  6. vue教程3-03 vue组件,定义全局、局部组件,配合模板,动态组件

    vue教程3-03 vue组件,定义全局.局部组件,配合模板,动态组件 一.定义一个组件 定义一个组件: 1. 全局组件 var Aaa=Vue.extend({ template:'<h3&g ...

  7. Vue把父组件的方法传递给子组件调用(评论列表例子)

    Vue把父组件的方法传递给子组件调用(评论列表例子) 效果展示: 相关Html: <!DOCTYPE html> <html lang="en"> < ...

  8. Vue动态注册异步组件(非同一个工程的组件)

    前言:最近在掘金逛的时候,无意中看到前滴滴前端架构黄轶大佬,看到了大佬分享的一篇博客滴滴 webapp 5.0 Vue 2.0 重构经验分享 ,对于其中第5个问题(异步加载的业务线组件,如何动态注册? ...

  9. 如何在vue中修改动态标签中的样式和修改组件库样式

    vue中修改动态标签中的样式和修改组件库样式 因为vue中的标签在渲染的时候,都会给标签加上id 所以你想在<style lang="scss" scoped>直接修改 ...

  10. Vue3组件(九)Vue + element-Plus + json = 动态渲染的表单控件

    一个成熟的表单 表单表单,你已经长大了,你要学会: 动态渲染 支持单列.双列.多列 支持调整布局 支持表单验证 支持调整排列(显示)顺序 依据组件值显示需要的组件 支持 item 扩展组件 可以自动创 ...

随机推荐

  1. Sprint产品待办列表的优先级要怎么排?

    在梳理产品待办事项列表的过程中,产品负责人需要先做优先级排列,保证我们 在一定的时间盒内能够交付需要优先级最高.最具价值的用户故事. 那这个用户故事的优先级要怎么排列,我们怎样选择用户故事的实现顺序? ...

  2. .NET周报【11月第1期 2022-11-07】

    国内文章 开源·安全·赋能 - .NET Conf China 2022 https://mp.weixin.qq.com/s/_tYpfPeQgyEGsnR4vVLzHg .NET Conf Chi ...

  3. [数据结构-线性表1.2] 链表与 LinkedList<T>(.NET 源码学习)

    [数据结构-线性表1.2] 链表与 LinkedList<T> [注:本篇文章源码内容较少,分析度较浅,请酌情选择阅读] 关键词:链表(数据结构)    C#中的链表(源码)    可空类 ...

  4. 04 uniapp/微信小程序 项目day04

    一.加入购物车 1.1 购物车数量 先创建购物车git 这里的数据肯定要做全局数据,因为不能只在details这个页面去操作他,他到底有几个也是由购物车页面获取到的 所以需要vuex 创建store文 ...

  5. perl遍历哈希的所有健和值

    my %h=("001",{name,"李白",age,"18",height,"185",weight,"6 ...

  6. htaccess如何配置隐藏index.php文件

    <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{RE ...

  7. tp6 requset获取参数的方式

    第一种:获取全部参数的值 request()->param() 1 第二种:获取排除某些字段的值,即获取其他值 request()->except(['serverToken','logi ...

  8. linux全新机器环境搭建流程梳理

    软件解压后安装基础指令(复制用):./configure && make && make install ./configure --prefix=/usr/local ...

  9. 各类数据库写入Webhsell总结

    1.MySQL写入WebShell 1.1写入条件 数据库的当前用户为ROOT或拥有FILE权限: 知道网站目录的绝对路径: PHP的GPC参数为off状态: MySQL中的secure_file_p ...

  10. log4j漏洞原理

    一.前置知识 1.JNDI接口 JNDI即Java Naming and Directory Interface(JAVA命名和目录接口),它提供一个目录系统,并将服务名称与对象关联起来,从而使得开发 ...