Skip to content

Instantly share code, notes, and snippets.

@jeovazero
Created October 24, 2019 16:58
Show Gist options
  • Save jeovazero/43c7157a5ee9c114de241007fc875849 to your computer and use it in GitHub Desktop.
Save jeovazero/43c7157a5ee9c114de241007fc875849 to your computer and use it in GitHub Desktop.
function fake(card) {
const el = document.querySelector(card)
console.log(el)
const bounds = el.getBoundingClientRect()
const { x, y } = bounds
const down = new MouseEvent('mousedown', {
bubbles: true,
clientX: x + 10,
clientY: y + 10,
button: 0
})
const move = new MouseEvent('mousemove', {
bubbles: true,
clientX: x + 10,
clientY: y + 50,
button: 0
})
const up = new MouseEvent('mouseup', {
bubbles: true,
clientX: x + 10,
clientY: y + 50,
button: 0
})
console.log(el.dispatchEvent(down))
document.querySelector(card).dispatchEvent(move)
console.log(document.querySelector(card).getBoundingClientRect())
document.querySelector(card).dispatchEvent(up)
}
fake('.card')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment