Skip to content

Commit 41f11f0

Browse files
author
=
committed
Using promise to fix vue-router with transition issue.
Fix Vue issue vuejs/vue-router#1758 Add html scroll-behavior to smooth to let scroll smoothly. (IE Safari not support this)
1 parent 81dc68c commit 41f11f0

File tree

7 files changed

+710
-585
lines changed

7 files changed

+710
-585
lines changed

.idea/workspace.xml

+130-103
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/app.css

+4
Original file line numberDiff line numberDiff line change
@@ -6576,6 +6576,10 @@ table {
65766576
src: url("/css/font/Futura_PT.otf") format("opentype");
65776577
}
65786578

6579+
html {
6580+
scroll-behavior: smooth;
6581+
}
6582+
65796583
a {
65806584
color: #22292f;
65816585
text-decoration: none;

public/js/app.js

+540-469
Large diffs are not rendered by default.

resources/js/routes.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,22 @@ export default new VueRouter({
8181
routes,
8282
linkActiveClass: 'is-active',
8383
linkExactActiveClass: 'is-exact-active',
84-
scrollBehavior(to) {
85-
if (to.hash) return {selector: to.hash}; // 如果有指定hash的話滾動到hash的位置
84+
scrollBehavior(to, from, savedPosition) {
85+
if (savedPosition) return savedPosition;
86+
87+
// Vue router transition issue while using anchor, need to use promise to async execute and delay after transition render finish.
88+
if (to.hash) {
89+
return new Promise((resolve) => {
90+
setTimeout(() => {
91+
resolve({selector: to.hash}); // 如果有指定hash的話滾動到hash的位置
92+
}, 600);
93+
});
94+
}
8695

8796
return new Promise((resolve) => {
8897
setTimeout(() => {
89-
resolve({ x: 0, y: 0 })
90-
}, 500)
98+
resolve({ x: 0, y: 0 }); // scroll to (0, 0)
99+
}, 500);
91100
})
92101
}
93102
});

resources/js/views/Home.vue

+16-6
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@
6565
data-aos="zoom-in-up"
6666
>
6767
<ul class="flex lg:flex-row flex-col justify-center items-center py-4">
68+
6869
<li class="tw-thumbnail lg:w-1/3 w-full p-4">
69-
<a href="/" class="flex lg:flex-col justify-center relative sm:pt-0 pt-8">
70+
<router-link tag="a"
71+
:to="{path: '/salon', hash: '#js-milano'}"
72+
class="flex lg:flex-col justify-center relative sm:pt-0 pt-8"
73+
>
7074
<figure class="w-2/5 sm:w-1/2 md:w-1/3 lg:w-full">
7175
<img src="/store/MILANO.jpg" alt="MILANO">
7276
</figure>
@@ -82,11 +86,14 @@
8286

8387
<p class="xl:text-sm text-xs relative sm:pl-8">サロン紹介 & ご予約</p>
8488
</div>
85-
</a>
89+
</router-link>
8690
</li>
8791

8892
<li class="tw-thumbnail lg:w-1/3 w-full p-4">
89-
<a href="/" class="flex lg:flex-col justify-center relative sm:pt-0 pt-8">
93+
<router-link tag="a"
94+
:to="{path: '/salon', hash: '#js-la-rochelle'}"
95+
class="flex lg:flex-col justify-center relative sm:pt-0 pt-8"
96+
>
9097
<figure class="w-2/5 sm:w-1/2 md:w-1/3 lg:w-full">
9198
<img src="/store/La_Rochelle.jpg" alt="La Rochelle">
9299
</figure>
@@ -102,11 +109,14 @@
102109

103110
<p class="xl:text-sm text-xs relative sm:pl-8">サロン紹介 & ご予約</p>
104111
</div>
105-
</a>
112+
</router-link>
106113
</li>
107114

108115
<li class="tw-thumbnail lg:w-1/3 w-full p-4">
109-
<a href="/" class="flex lg:flex-col justify-center relative sm:pt-0 pt-8">
116+
<router-link tag="a"
117+
:to="{path: '/salon', hash: '#js-lisbon'}"
118+
class="flex lg:flex-col justify-center relative sm:pt-0 pt-8"
119+
>
110120
<figure class="w-2/5 sm:w-1/2 md:w-1/3 lg:w-full">
111121
<img src="/store/LISBON.jpg" alt="LISBON">
112122
</figure>
@@ -122,7 +132,7 @@
122132

123133
<p class="xl:text-sm text-xs relative sm:pl-8">サロン紹介 & ご予約</p>
124134
</div>
125-
</a>
135+
</router-link>
126136
</li>
127137
</ul>
128138
</li>

resources/js/views/Salon.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</hero-bg>
1313

1414
<!-- sec 01 -->
15-
<section class="mb-24 relative">
15+
<section class="mb-24 relative" id="js-milano">
1616
<div class="max-w-1000 mx-auto p-4">
1717
<div class="flex flex-col md:flex-row">
1818
<div
@@ -59,7 +59,7 @@
5959
</section>
6060

6161
<!-- sec 02 -->
62-
<section class="mb-24 relative">
62+
<section class="mb-24 relative" id="js-la-rochelle">
6363
<div class="max-w-1000 mx-auto p-4">
6464
<div class="flex flex-col md:flex-row">
6565
<div class="lg:w-1/2 w-full bg-white p-16 pt-8 border border-gold mb-16 md:my-16 md:mx-8 relative">
@@ -105,7 +105,7 @@
105105
</section>
106106

107107
<!-- sec 03 -->
108-
<section class="mb-24 relative">
108+
<section class="mb-24 relative" id="js-lisbon">
109109
<div class="max-w-1000 mx-auto p-4">
110110
<div class="flex flex-col md:flex-row">
111111
<div class="lg:w-1/2 w-full bg-white p-16 pt-8 border border-blue-lighter mb-16 md:my-16 md:mx-8 relative tw-flex-end">

resources/sass/app.scss

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
src: url("/css/font/Futura_PT.otf") format("opentype");
1515
}
1616

17+
html {
18+
scroll-behavior: smooth;
19+
}
20+
1721
a {
1822
@apply text-black no-underline;
1923
}

0 commit comments

Comments
 (0)