Commit c1223a0b2ad95c388ad94570a7790074d7afbd6e
1 parent
f3042649
横向滚动宽度计算,结果向上取整,取到的值一定大于等于原值,有小数就+1
Showing
1 changed file
with
4 additions
and
4 deletions
src/components/horizList/horizList.vue
| @@ -102,16 +102,16 @@ | @@ -102,16 +102,16 @@ | ||
| 102 | let scrollItemBox = 0; | 102 | let scrollItemBox = 0; |
| 103 | let clientWidth = wrapper.clientWidth; | 103 | let clientWidth = wrapper.clientWidth; |
| 104 | let multiple = clientWidth / 750; | 104 | let multiple = clientWidth / 750; |
| 105 | - let childrens = wrapper.children[0].children; | 105 | + let childrens = wrapper.children[0].children; |
| 106 | 106 | ||
| 107 | // 遍历子元素,获取box宽度 | 107 | // 遍历子元素,获取box宽度 |
| 108 | for (let i = 0; i < childrens.length; i++) { | 108 | for (let i = 0; i < childrens.length; i++) { |
| 109 | - scrollItemBox += childrens[i].clientWidth; | ||
| 110 | - } | 109 | + scrollItemBox += childrens[i].clientWidth; |
| 110 | + } | ||
| 111 | 111 | ||
| 112 | // 根据屏幕比例计算实际设置vw值 | 112 | // 根据屏幕比例计算实际设置vw值 |
| 113 | // scrollItemBox = (scrollItemBox + ((30 * multiple * (childrens.length - 1)))) / clientWidth * this.basicWidth; | 113 | // scrollItemBox = (scrollItemBox + ((30 * multiple * (childrens.length - 1)))) / clientWidth * this.basicWidth; |
| 114 | - scrollItemBox = ((scrollItemBox + (0 * multiple)) / clientWidth * this.basicWidth); | 114 | + scrollItemBox = Math.ceil(((scrollItemBox + (0 * multiple)) / clientWidth * this.basicWidth)); |
| 115 | 115 | ||
| 116 | // 判断scrollItemBox值,更新this.scrollItemBox宽度 | 116 | // 判断scrollItemBox值,更新this.scrollItemBox宽度 |
| 117 | if (scrollItemBox > this.basicWidth) { | 117 | if (scrollItemBox > this.basicWidth) { |