Showing
1 changed file
with
10 additions
and
4 deletions
| ... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
| 18 | :rules="rules" | 18 | :rules="rules" |
| 19 | :required="item.component_props.required" | 19 | :required="item.component_props.required" |
| 20 | readonly | 20 | readonly |
| 21 | - @touchstart.stop="openKeyboard()" | 21 | + @touchstart.stop="openKeyboard($event)" |
| 22 | :border="false" | 22 | :border="false" |
| 23 | > | 23 | > |
| 24 | </van-field> | 24 | </van-field> |
| ... | @@ -41,11 +41,17 @@ const props = defineProps({ | ... | @@ -41,11 +41,17 @@ const props = defineProps({ |
| 41 | 41 | ||
| 42 | const show = ref(false); | 42 | const show = ref(false); |
| 43 | 43 | ||
| 44 | -const openKeyboard = () => { | 44 | +const openKeyboard = (e) => { |
| 45 | show.value = true; | 45 | show.value = true; |
| 46 | // 键盘上移动 | 46 | // 键盘上移动 |
| 47 | - document.body.style.paddingBottom = "100px"; | 47 | + const height = |
| 48 | - document.documentElement.scrollTop = 100; | 48 | + window.innerHeight - |
| 49 | + e.target.getBoundingClientRect().y - | ||
| 50 | + e.target.getBoundingClientRect().height + | ||
| 51 | + 50; | ||
| 52 | + document.body.style.paddingBottom = height + "px"; | ||
| 53 | + document.documentElement.scrollTop = height; | ||
| 54 | + console.warn(height); | ||
| 49 | }; | 55 | }; |
| 50 | const blurKeyboard = () => { | 56 | const blurKeyboard = () => { |
| 51 | show.value = false; | 57 | show.value = false; | ... | ... |
-
Please register or login to post a comment