File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed
starter/07-Omnifood-Desktop Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ Medium 11px
64
64
html {
65
65
font-size : 62.5% ;
66
66
overflow-x : hidden;
67
+ /* Does NOT work on Safari */
68
+ /* scroll-behavior: smooth; */
67
69
}
68
70
69
71
body {
Original file line number Diff line number Diff line change 54
54
< li >
55
55
< a
56
56
class ="main-nav-link nav-cta "
57
- href ="#try-for-free "
57
+ href ="#cta "
58
58
alt ="Main Nav Section Item "
59
59
> Try for free</ a
60
60
>
@@ -80,10 +80,12 @@ <h1 class="heading-primary">
80
80
eat healthy again. Tailored to your personal tastes and
81
81
nutritional needs.
82
82
</ p >
83
- < a href ="# " class ="btn btn--full margin-right-sm "
83
+ < a href ="#cta " class ="btn btn--full margin-right-sm "
84
84
> Start eating well</ a
85
85
>
86
- < a href ="# " class ="btn btn--outline "> Learn more ↓</ a >
86
+ < a href ="#how-it-works " class ="btn btn--outline "
87
+ > Learn more ↓</ a
88
+ >
87
89
< div class ="delivered-meals ">
88
90
< div class ="delivered-img ">
89
91
< img src ="img/customers/customer-1.jpg " alt ="Customer photo " />
@@ -595,7 +597,7 @@ <h2 class="heading-secondary">
595
597
</ div >
596
598
</ section >
597
599
598
- < section class ="section-cta " id ="try-for-free ">
600
+ < section class ="section-cta " id ="cta ">
599
601
< div class ="container ">
600
602
< div class ="cta ">
601
603
< div class ="cta-text-box ">
@@ -733,6 +735,10 @@ <h2 class="heading-secondary">Get your first meal for free!</h2>
733
735
nomodule
734
736
src ="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js "
735
737
> </ script >
738
+ < script
739
+ defer
740
+ src ="https://unpkg.com/smoothscroll-polyfill@0.4.4/dist/smoothscroll.min.js "
741
+ > </ script >
736
742
< script defer src ="js/script.js "> </ script >
737
743
</ body >
738
744
</ html >
Original file line number Diff line number Diff line change @@ -30,6 +30,35 @@ btnMobileNavEl.addEventListener("click", function () {
30
30
headerEl . classList . toggle ( "nav-open" ) ;
31
31
} ) ;
32
32
33
+ /////////////////////////////////////////////////////////////////////////////
34
+ // Smooth scrolling animation
35
+ const allLinks = document . querySelectorAll ( "a:link" ) ;
36
+ allLinks . forEach ( ( link ) => {
37
+ link . addEventListener ( "click" , ( e ) => {
38
+ e . preventDefault ( ) ;
39
+ const href = link . getAttribute ( "href" ) ;
40
+
41
+ // Scroll back to top
42
+ if ( href === "#" ) {
43
+ window . scrollTo ( {
44
+ top : 0 ,
45
+ behavior : "smooth" ,
46
+ } ) ;
47
+ }
48
+
49
+ // Scroll to other links
50
+ if ( href !== "#" && href . startsWith ( "#" ) ) {
51
+ const section = document . querySelector ( href ) ;
52
+ section . scrollIntoView ( { behavior : "smooth" } ) ;
53
+ }
54
+
55
+ // Close mobile navigation
56
+ if ( link . classList . contains ( "main-nav-link" ) ) {
57
+ headerEl . classList . toggle ( "nav-open" ) ;
58
+ }
59
+ } ) ;
60
+ } ) ;
61
+
33
62
// https://unpkg.com/smoothscroll-polyfill@0.4.4/dist/smoothscroll.min.js
34
63
35
64
/*
You can’t perform that action at this time.
0 commit comments