Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiguangyao
mr-julyedu
Commits
c5c0ef53
Commit
c5c0ef53
authored
Oct 30, 2019
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
banner
parent
34e7ac4d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
10 deletions
+95
-10
src/components/blessingPreheat/banner/index.js
+84
-10
src/components/blessingPreheat/banner/index.scss
+11
-0
No files found.
src/components/blessingPreheat/banner/index.js
View file @
c5c0ef53
import
React
,
{
Component
}
from
'react'
import
'./index.scss'
import
{
throttle
}
from
'lodash'
class
Banner
extends
Component
{
navTop
=
183
prevY
=
0
state
=
{
navs
:
[
{
text
:
'积福气'
text
:
'积福气'
,
id
:
'lucky-value'
},
{
text
:
'幸运大抽奖'
text
:
'幸运大抽奖'
,
id
:
'lucky-draw'
},
{
text
:
'预付定金'
text
:
'预付定金'
,
id
:
'deposit'
},
{
text
:
'精品特惠'
text
:
'精品特惠'
,
id
:
'best-courses'
},
{
text
:
'AI测试'
text
:
'AI测试'
,
id
:
'ai-test'
},
{
text
:
'大咖直播'
text
:
'大咖直播'
,
id
:
'live'
},
]
],
index
:
0
,
}
componentDidMount
()
{
window
.
addEventListener
(
'scroll'
,
throttle
(
this
.
calcNavActive
,
100
))
}
componentWillUnmount
()
{
}
calcNavActive
=
()
=>
{
const
{
navs
,
index
}
=
this
.
state
const
y
=
window
.
scrollY
let
swipeDirection
=
y
>
this
.
prevY
?
'up'
:
'down'
let
_index
if
(
swipeDirection
===
'up'
)
{
_index
=
(
index
+
1
)
>=
navs
.
length
?
index
:
index
+
1
}
else
{
_index
=
(
index
-
1
)
<=
0
?
0
:
index
-
1
}
let
el
=
document
.
querySelector
(
`#
${
navs
[
_index
].
id
}
`
)
let
nav
=
document
.
querySelector
(
'#main-nav'
)
let
top
=
el
.
offsetTop
if
(
y
<=
this
.
navTop
)
{
nav
.
classList
.
remove
(
'fixed'
)
}
else
{
!
nav
.
classList
.
contains
(
'fixed'
)
&&
nav
.
classList
.
add
(
'fixed'
)
}
if
(
swipeDirection
===
'up'
)
{
if
(
y
+
30
+
30
>=
top
)
{
this
.
setState
({
index
:
_index
})
}
}
else
{
if
(
y
+
30
+
20
<=
top
)
{
this
.
setState
({
index
:
_index
})
}
}
this
.
prevY
=
y
}
toSection
=
(
i
,
e
)
=>
{
e
.
preventDefault
()
let
top
=
document
.
querySelector
(
`#
${
this
.
state
.
navs
[
i
].
id
}
`
).
offsetTop
this
.
setState
({
index
:
i
})
window
.
scrollTo
({
top
:
top
-
60
,
left
:
0
})
}
render
()
{
const
{
navs
}
=
this
.
state
const
{
navs
,
index
}
=
this
.
state
return
(
<
div
id
=
{
'main-banner'
}
>
<
div
className
=
"banner"
><
/div
>
<
nav
id
=
{
'main-nav'
}
>
<
ul
>
{
navs
.
map
((
item
,
i
ndex
)
=>
{
navs
.
map
((
item
,
i
)
=>
{
return
(
<
li
key
=
{
index
}
>
{
item
.
text
}
<
/li
>
<
li
key
=
{
i
}
className
=
{
index
===
i
?
'active'
:
''
}
>
<
a
href
=
{
`#
${
item
.
id
}
`
}
onClick
=
{(
e
)
=>
{
this
.
toSection
(
i
,
e
)
}}
>
{
item
.
text
}
<
/a
>
<
/li
>
)
})
}
...
...
src/components/blessingPreheat/banner/index.scss
View file @
c5c0ef53
#main-banner
{
overflow
:
auto
;
.banner
{
width
:
375px
;
height
:
183px
;
...
...
@@ -6,7 +7,14 @@
background-size
:
contain
;
}
#main-nav
{
position
:
absolute
;
top
:
183px
;
margin-bottom
:
30px
;
&
.fixed
{
position
:
fixed
;
top
:
0
;
z-index
:
100
;
}
ul
{
background
:
#3900C9
;
display
:
flex
;
...
...
@@ -18,6 +26,9 @@
color
:
#fff
;
text-align
:
center
;
line-height
:
30px
;
&
.active
{
background
:
#FF42F9
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment