|
| 1 | +:::anchor scrollTo |
| 2 | + |
| 3 | +:::demo 1、Params refer to [scrollTo](https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollTo) |
| 4 | + |
| 5 | +```html |
| 6 | +<template> |
| 7 | + <div> |
| 8 | + <div style="margin-bottom:20px;line-height:3.0;"> |
| 9 | + <button class="button-demo" @click="scrollY(1000)">Scroll vertically to 1000px</button> |
| 10 | + <button class="button-demo" @click="scrollY(500)">Scroll vertically to 500px</button> |
| 11 | + <button class="button-demo" @click="scrollY(0)">Scroll vertically to 0px</button> |
| 12 | + <button class="button-demo" @click="scrollX(500)">Scroll horizontally to 300px</button> |
| 13 | + <button class="button-demo" @click="scrollX(300)">Scroll horizontally to 200px</button> |
| 14 | + <button class="button-demo" @click="scrollX(0)">Scroll horizontally to 0px</button> |
| 15 | + </div> |
| 16 | + <ve-table |
| 17 | + ref="tableRef" |
| 18 | + style="width:1000px" |
| 19 | + :scroll-width="1600" |
| 20 | + :max-height="350" |
| 21 | + border-y |
| 22 | + :columns="columns" |
| 23 | + :table-data="tableData" |
| 24 | + rowKeyFieldName="rowkey" |
| 25 | + /> |
| 26 | + </div> |
| 27 | +</template> |
| 28 | + |
| 29 | +<script> |
| 30 | + export default { |
| 31 | + data() { |
| 32 | + return { |
| 33 | + columns: [ |
| 34 | + { field: "col1", key: "a", title: "Title1", fixed: "left" }, |
| 35 | + { field: "col2", key: "b", title: "Title2", fixed: "left" }, |
| 36 | + { field: "col3", key: "c", title: "Title3" }, |
| 37 | + { field: "col4", key: "d", title: "Title4" }, |
| 38 | + { field: "col5", key: "e", title: "Title5" }, |
| 39 | + { field: "col6", key: "f", title: "Title6" }, |
| 40 | + { field: "col7", key: "g", title: "Title7" }, |
| 41 | + { field: "col8", key: "h", title: "Title8" }, |
| 42 | + { |
| 43 | + field: "col9", |
| 44 | + key: "i", |
| 45 | + title: "Title9", |
| 46 | + fixed: "right", |
| 47 | + }, |
| 48 | + { |
| 49 | + field: "col10", |
| 50 | + key: "j", |
| 51 | + title: "Title10", |
| 52 | + fixed: "right", |
| 53 | + }, |
| 54 | + ], |
| 55 | + }; |
| 56 | + }, |
| 57 | + methods: { |
| 58 | + initTableData() { |
| 59 | + let data = []; |
| 60 | + for (let i = 0; i < 80; i++) { |
| 61 | + data.push({ |
| 62 | + rowkey: i, |
| 63 | + col1: i, |
| 64 | + col2: i, |
| 65 | + col3: i, |
| 66 | + col4: i, |
| 67 | + col5: i, |
| 68 | + col6: i, |
| 69 | + col7: i, |
| 70 | + col8: i, |
| 71 | + col9: i, |
| 72 | + col10: i, |
| 73 | + }); |
| 74 | + } |
| 75 | + this.tableData = data; |
| 76 | + }, |
| 77 | + // scroll y |
| 78 | + scrollY(val) { |
| 79 | + this.$refs["tableRef"].scrollTo({ top: val, behavior: "smooth" }); |
| 80 | + }, |
| 81 | + // scroll x |
| 82 | + scrollX(val) { |
| 83 | + this.$refs["tableRef"].scrollTo({ left: val, behavior: "smooth" }); |
| 84 | + }, |
| 85 | + }, |
| 86 | + created() { |
| 87 | + this.initTableData(); |
| 88 | + }, |
| 89 | + }; |
| 90 | +</script> |
| 91 | +``` |
| 92 | + |
| 93 | +::: |
0 commit comments