| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <template>
- <div class="site-bar" v-show="1">
- <div class="btn wechat">
- <svg-icon icon-class="wechat" />
- <img class="show-img z-50" :src="wechatSrc" alt="">
- </div>
- <div class="btn top" @click="toTop" >
- <svg-icon icon-class="top" />
- </div>
- </div>
- </template>
- <script>
- // 网页侧边栏小工具
- export default {
- name: "siteBar",
- props:{
- lang: {
- type: String,
- default: 'cn'
- },
- wechatSrc: {
- type: String,
- default: ''
- }
- },
- // 指令
- directives:{
- // 滚动超过一屏时显示元素,否则隐藏
- show:{
- inserted(el){
- const elHeight = el.offsetHeight;
- const winHeight = window.innerHeight;
- const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- if (elHeight + scrollTop > winHeight){
- el.style.display = 'block';
- }else{
- el.style.display = 'none';
- }
- window.addEventListener('scroll',()=>{
- const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- if (elHeight + scrollTop > winHeight){
- el.style.display = 'block';
- }else{
- el.style.display = 'none';
- }
- })
- }
- }
- },
- methods: {
- toTop() {
- // 缓慢移动到顶部
- window.scrollTo({
- top: 0,
- behavior: "smooth"
- });
- }
- }
- }
- </script>
- <style scoped>
- .site-bar{
- width: 50px;
- height: auto;
- position: fixed;
- right: 30px;
- bottom: 30px;
- /*transform: translateY(-50%);*/
- }
- @media screen and (min-width: 1024px) {
- .site-bar{
- right: 180px;
- bottom: 26%;
- }
- }
- .site-bar .btn{
- width: 50px;
- height: 50px;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 2rem;
- cursor: pointer;
- background-color: #f5f5f5;
- border-radius: 50%;
- box-shadow: 0 0 5px #dedede;
- color: #999999;
- margin-bottom: 10px;
- }
- .site-bar .btn:hover{
- background-color: #dedede;
- color: #af4141;
- }
- .wechat{
- position: relative;
- }
- .wechat .show-img{
- position: absolute;
- bottom: 50px;
- right: 50px;
- display: block;
- width: 0;
- height: 0;
- max-width: none;
- border-radius: 5px;
- box-shadow: 1px 1px 7px 5px #dedede;
- opacity: 0;
- transition: all 0.5s;
- }
- .wechat:hover .show-img{
- opacity: 1;
- width: 180px;
- height: 180px;
- }
- </style>
|