Skip to content

Commit c93105f

Browse files
author
reco_luan
committed
fix: friend link
1 parent 236e506 commit c93105f

File tree

1 file changed

+80
-22
lines changed

1 file changed

+80
-22
lines changed

components/FriendLink.vue

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,30 @@
1313
</span>
1414
{{item.title}}
1515
</div>
16-
<div @mouseenter="showDetailStatus = true" class="popup-window" v-if="showDetailStatus" :style="popupWindowStyle" ref="popupWindow">
17-
<div class="avatar">
18-
<img :src="`http://1.gravatar.com/avatar/${getMd5('recoluan@qq.com' || '')}?s=50&amp;d=mm&amp;r=x`" />
19-
</div>
20-
<div class="info">
21-
<div class="title">
22-
<h4>{{ detailData.title }}</h4>
23-
<a
24-
class="btn-go"
25-
:style="{ 'backgroundColor': _tagColor() }"
26-
:href="detailData.link"
27-
target="_blank">GO</a>
16+
<transition name="fade">
17+
<div
18+
@mouseenter="windowEnter"
19+
@mouseleave="windowLeave"
20+
class="popup-window"
21+
v-if="showDetailStatus"
22+
:style="popupWindowStyle"
23+
ref="popupWindow">
24+
<div class="avatar">
25+
<img :src="`http://1.gravatar.com/avatar/${getMd5(detailData.email || '')}?s=50&amp;d=mm&amp;r=x`" />
26+
</div>
27+
<div class="info">
28+
<div class="title">
29+
<h4>{{ detailData.title }}</h4>
30+
<a
31+
class="btn-go"
32+
:style="{ 'backgroundColor': _tagColor() }"
33+
:href="detailData.link"
34+
target="_blank">GO</a>
35+
</div>
36+
<p>{{ detailData.desc }}</p>
2837
</div>
29-
<p>Enjoy when you can, and endure when you must.</p>
3038
</div>
31-
</div>
39+
</transition>
3240
</div>
3341
</template>
3442

@@ -42,28 +50,73 @@ export default {
4250
return {
4351
detailData: {},
4452
showDetailStatus: false,
45-
popupWindowStyle: {}
53+
popupWindowStyle: {},
54+
btnEnterStatus: false,
55+
windowEnterStatus: false
4656
}
4757
},
4858
methods: {
4959
getMd5 (str) {
5060
return md5(str)
5161
},
5262
showDetail (e, info) {
63+
this.btnEnterStatus = true
5364
const currentDom = e.target
54-
const { offsetTop, offsetLeft, clientWidth, clientHeight } = currentDom
55-
console.log(clientWidth)
56-
const { offsetX, offsetY } = e
65+
const { offsetTop, offsetLeft, clientWidth } = currentDom
5766
this.popupWindowStyle = {
58-
left: ((offsetLeft + clientWidth) - 300) / 2 + 'px',
59-
top: ((offsetTop + clientHeight) / 2) - 155 + 'px'
67+
left: ((offsetLeft + clientWidth / 2) - 300 / 2) + 'px',
68+
top: (offsetTop - 150) + 'px'
6069
}
6170
this.detailData = info
6271
this.showDetailStatus = true
72+
this.$nextTick(() => {
73+
this._adjustPosition()
74+
})
6375
},
6476
hideDetail () {
65-
this.showDetailStatus = false
66-
this.detailData = {}
77+
// this.btnEnterStatus = false
78+
// if (this.windowEnterStatus === false) this.showDetailStatus = false
79+
},
80+
windowEnter () {
81+
this.windowEnterStatus = true
82+
this.showDetailStatus = true
83+
},
84+
windowLeave () {
85+
// this.windowEnterStatus = false
86+
// if (this.btnEnterStatus === false) this.showDetailStatus = false
87+
},
88+
_adjustPosition () {
89+
const { offsetWidth } = document.body
90+
const { x, width } = this.$refs.popupWindow.getBoundingClientRect()
91+
const distanceToRight = offsetWidth - (x + width)
92+
if (distanceToRight < 0) {
93+
const { offsetLeft } = this.$refs.popupWindow
94+
this.popupWindowStyle = {
95+
...this.popupWindowStyle,
96+
left: offsetLeft + distanceToRight + 'px'
97+
}
98+
}
99+
}
100+
},
101+
watch: {
102+
showDetailStatus (val) {
103+
if (val) {
104+
let [prevX, prevY, nextX, nextY] = [0, 0, 0, 0]
105+
106+
window.addEventListener('mouseend', (e) => {
107+
prevX = nextX
108+
prevY = nextY
109+
nextX = e.x
110+
nextY = e.y
111+
// console.log(prevX, prevY, nextX, nextY)
112+
console.log(Math.atan2(nextY - prevY, nextX - prevX))
113+
if (Math.atan2(nextY - prevY, nextX - prevX) > -1.75 && Math.atan2(nextY - prevY, nextX - prevX)< -0.75) {
114+
this.showDetailStatus = true
115+
} else {
116+
this.showDetailStatus = false
117+
}
118+
})
119+
}
67120
}
68121
}
69122
}
@@ -136,4 +189,9 @@ export default {
136189
text-align center
137190
line-height 1.2rem
138191
cursor pointer
192+
193+
.fade-enter-active, .fade-leave-active
194+
transition opacity .5s
195+
.fade-enter, .fade-leave-to
196+
opacity 0
139197
</style>

0 commit comments

Comments
 (0)