Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VueElementTemplate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
HireTest
VueElementTemplate
Commits
5069a4d1
Commit
5069a4d1
authored
Jul 17, 2017
by
dongsuo
Committed by
花裤衩
Jul 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'修改返回顶部功能'
parent
bf087566
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
30 deletions
+64
-30
index.vue
src/components/BackToTop/index.vue
+42
-23
backToTop.vue
src/views/components/backToTop.vue
+22
-7
No files found.
src/components/BackToTop/index.vue
View file @
5069a4d1
<
template
>
<
template
>
<transition
name=
"fade"
>
<transition
:name=
"transitionName"
>
<div
class=
"back-to-top"
@
click=
"backToTop"
v-show=
"visible"
>
<div
class=
"back-to-top"
@
click=
"backToTop"
v-show=
"visible"
:style=
"customStyle"
>
<el-tooltip
class=
"item"
effect=
"dark"
content=
"返回顶部"
placement=
"top"
>
<svg
width=
"16"
height=
"16"
viewBox=
"0 0 17 17"
xmlns=
"http://www.w3.org/2000/svg"
class=
"Icon Icon--backToTopArrow"
aria-hidden=
"true"
style=
"height: 16px; width: 16px;"
>
<i
class=
"el-icon-arrow-up"
></i>
<title>
回到顶部
</title>
</el-tooltip>
<g>
<path
d=
"M12.036 15.59c0 .55-.453.995-.997.995H5.032c-.55 0-.997-.445-.997-.996V8.584H1.03c-1.1 0-1.36-.633-.578-1.416L7.33.29c.39-.39 1.026-.385 1.412 0l6.878 6.88c.782.78.523 1.415-.58 1.415h-3.004v7.004z"
fill-rule=
"evenodd"
></path>
</g>
</svg>
</div>
</div>
</transition>
</transition>
</
template
>
</
template
>
...
@@ -18,18 +21,39 @@ export default {
...
@@ -18,18 +21,39 @@ export default {
backPosition
:
{
backPosition
:
{
type
:
Number
,
type
:
Number
,
default
:
0
default
:
0
},
customStyle
:
{
type
:
Object
,
default
:
{
right
:
'50px'
,
bottom
:
'50px'
,
width
:
'40px'
,
height
:
'40px'
,
'border-radius'
:
'4px'
,
'line-height'
:
'40px'
,
background
:
'#e7eaf1'
}
},
transitionName
:
{
type
:
String
,
default
:
'fade'
}
}
},
},
data
()
{
data
()
{
return
{
return
{
visible
:
false
visible
:
false
,
interval
:
null
}
}
},
},
mounted
()
{
mounted
()
{
window
.
addEventListener
(
'scroll'
,
this
.
handleScroll
)
window
.
addEventListener
(
'scroll'
,
this
.
handleScroll
)
;
},
},
beforeDestroy
()
{
beforeDestroy
()
{
window
.
removeEventListener
(
'scroll'
,
this
.
handleScroll
)
window
.
removeEventListener
(
'scroll'
,
this
.
handleScroll
);
if
(
this
.
interval
)
{
clearInterval
(
this
.
interval
);
}
},
},
methods
:
{
methods
:
{
handleScroll
()
{
handleScroll
()
{
...
@@ -38,11 +62,11 @@ export default {
...
@@ -38,11 +62,11 @@ export default {
backToTop
()
{
backToTop
()
{
const
start
=
window
.
pageYOffset
;
const
start
=
window
.
pageYOffset
;
let
i
=
0
;
let
i
=
0
;
const
t
=
setInterval
(()
=>
{
this
.
interval
=
setInterval
(()
=>
{
const
next
=
Math
.
floor
(
this
.
easeInOutQuad
(
10
*
i
,
start
,
-
start
,
500
));
const
next
=
Math
.
floor
(
this
.
easeInOutQuad
(
10
*
i
,
start
,
-
start
,
500
));
if
(
next
<=
this
.
backPosition
)
{
if
(
next
<=
this
.
backPosition
)
{
window
.
scrollTo
(
0
,
this
.
backPosition
);
window
.
scrollTo
(
0
,
this
.
backPosition
);
clearInterval
(
t
)
clearInterval
(
t
his
.
interval
)
}
else
{
}
else
{
window
.
scrollTo
(
0
,
next
);
window
.
scrollTo
(
0
,
next
);
}
}
...
@@ -59,21 +83,18 @@ export default {
...
@@ -59,21 +83,18 @@ export default {
<
style
scoped
>
<
style
scoped
>
.back-to-top
{
.back-to-top
{
position
:
fixed
;
position
:
fixed
;
right
:
50px
;
bottom
:
50px
;
display
:
inline-block
;
display
:
inline-block
;
height
:
40px
;
width
:
40px
;
box-shadow
:
1px
1px
1px
#58B7FF
;
text-align
:
center
;
text-align
:
center
;
cursor
:
pointer
;
cursor
:
pointer
;
background
:
#58B7FF
;
}
color
:
#fff
;
.back-to-top
:hover
{
background
:
#d5dbe7
;
}
}
.fade-enter-active
,
.fade-enter-active
,
.fade-leave-active
{
.fade-leave-active
{
transition
:
opacity
1s
transition
:
opacity
.5s
;
}
}
.fade-enter
,
.fade-enter
,
...
@@ -81,11 +102,9 @@ export default {
...
@@ -81,11 +102,9 @@ export default {
opacity
:
0
opacity
:
0
}
}
.back-to-top
i
{
.back-to-top
.Icon
{
display
:
inline-block
;
fill
:
#9aaabf
;
width
:
100%
;
background
:
none
;
height
:
100%
;
line-height
:
40px
;
}
}
</
style
>
</
style
>
...
...
src/views/components/backToTop.vue
View file @
5069a4d1
<
template
>
<
template
>
<div
class=
"components-container"
>
<div
class=
"components-container"
>
<code>
页面滚动到指定位置会在右下角出现返回顶部按钮
</code>
<code>
页面滚动到指定位置会在右下角出现返回顶部按钮
</code>
<code>
可自定义按钮的样式、show/hide临界点、返回的位置
如需文字提示,可在外部使用Element的el-tooltip元素
</code>
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
...
@@ -125,19 +127,32 @@
...
@@ -125,19 +127,32 @@
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
<div>
我是占位
</div>
<back-to-top
id=
"back-to-top-t"
:visibilityHeight=
"300"
:backPosition=
"50"
></back-to-top>
<!--可自定义按钮的样式、show/hide临界点、返回的位置 -->
<!--如需文字提示,可在外部添加element的
<el-tooltip></el-tooltip>
元素 -->
<el-tooltip
placement=
"top"
content=
"文字提示"
>
<back-to-top
transitionName=
"fade"
:customStyle=
"myBackToTopStyle"
:visibilityHeight=
"300"
:backPosition=
"50"
></back-to-top>
</el-tooltip>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
BackToTop
from
'components/BackToTop'
;
import
BackToTop
from
'components/BackToTop'
;
export
default
{
export
default
{
components
:
{
BackToTop
}
components
:
{
BackToTop
},
data
()
{
return
{
myBackToTopStyle
:
{
right
:
'50px'
,
bottom
:
'50px'
,
width
:
'40px'
,
height
:
'40px'
,
'border-radius'
:
'4px'
,
'line-height'
:
'40px'
,
// 请保持与高度一致以垂直居中
background
:
'#e7eaf1'
// 按钮的背景颜色
}
}
}
}
}
</
script
>
</
script
>
<
style
scoped
>
<
style
scoped
>
#back-to-top-t
{
right
:
100px
;
bottom
:
100px
;
}
</
style
>
</
style
>
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