Skip to content

Commit e4b0d4d

Browse files
author
Sebi Nemeth
committed
add draggable abspos demo
1 parent 7213972 commit e4b0d4d

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

src/demo/App.vue

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
<h3>Attribute</h3>
4848
<img class="image" src="https://source.unsplash.com/random/500x500" :alt="t('LTPlugin.Attrs.ImageAlt')"
4949
:title="t('LTPlugin.Attrs.ImageTitle')">
50+
51+
<div id="draggable" draggable @mousedown="dragStart" @mousemove="dragMove" @mouseup="dragEnd" ref="draggable" :title="t('LTPlugin.PositionAbsolute')">
52+
<h3>Absolute position</h3>
53+
{{ t('LTPlugin.Draggable') }}
54+
</div>
5055
</div>
5156
</div>
5257
</template>
@@ -66,6 +71,26 @@ const showMeta = computed(() => {
6671
return null
6772
})
6873
74+
const dragPos = ref<{ x: number, y: number } | null>(null)
75+
const draggable = ref<HTMLDivElement>()
76+
77+
function dragStart(e: MouseEvent) {
78+
dragPos.value = {
79+
x: e.offsetX,
80+
y: e.offsetY,
81+
}
82+
}
83+
84+
function dragMove(e: MouseEvent) {
85+
if (!dragPos.value) return
86+
draggable.value!.style.top = e.pageY - dragPos.value.y + 'px'
87+
draggable.value!.style.left = e.pageX - dragPos.value.x + 'px'
88+
}
89+
90+
function dragEnd() {
91+
dragPos.value = null
92+
}
93+
6994
</script>
7095

7196
<style lang="scss" scoped>
@@ -120,4 +145,32 @@ const showMeta = computed(() => {
120145
width: 80%;
121146
border-radius: 8px;
122147
}
148+
149+
#draggable {
150+
position: absolute;
151+
top: 8px;
152+
left: 8px;
153+
background: #eeeeeee2;
154+
width: 200px;
155+
height: 150px;
156+
display: flex;
157+
justify-content: center;
158+
align-items: center;
159+
border-radius: 8px;
160+
padding: 1rem;
161+
cursor: grab;
162+
flex-direction: column;
163+
164+
h3 {
165+
margin-top: 0;
166+
}
167+
168+
&:hover {
169+
outline: solid 2px #eeeeee;
170+
}
171+
172+
&:active {
173+
cursor: grabbing;
174+
}
175+
}
123176
</style>

src/demo/lang/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"PartOne": "Part one",
1212
"PartTwo": "Part two",
1313
"ListItemN": "Item {0}",
14-
"MultipleTitle": "Multiple strings inside one tag"
14+
"MultipleTitle": "Multiple strings inside one tag",
15+
"Draggable": "Drag me around to cover elements",
16+
"PositionAbsolute": "Position is absolute"
1517
}
1618
}

src/demo/lang/hu.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"PartOne": "Első rész",
1212
"PartTwo": "Második rész",
1313
"ListItemN": "Elem {0}",
14-
"MultipleTitle": "Több string egy tagen belül"
14+
"MultipleTitle": "Több string egy tagen belül",
15+
"Draggable": "Mozgass egy elem fölé, hogy eltakard azt",
16+
"PositionAbsolute": "'absolute' pozíció"
1517
}
1618
}

src/demo/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ app.use(LiveTranslatorPlugin, {
1313
},
1414
persist: true,
1515
root: document.getElementById('app'),
16-
refreshRate: 200,
16+
refreshRate: 50,
1717
})
1818

1919
app.mount('#app')

src/demo/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ body {
2828
place-items: center;
2929
min-width: 320px;
3030
min-height: 100vh;
31+
overflow-x: hidden;
3132
}
3233

3334
h1 {

0 commit comments

Comments
 (0)