I have a v-btn with ripple enabled. Is there a way to programmatically trigger the ripple effect? Is this possible if I use v-ripple directive on another ponent of my own that wraps the button?
I need to draw the users attention to the button in an unobtrusive way.
I have a v-btn with ripple enabled. Is there a way to programmatically trigger the ripple effect? Is this possible if I use v-ripple directive on another ponent of my own that wraps the button?
I need to draw the users attention to the button in an unobtrusive way.
Share Improve this question asked Jun 30, 2019 at 12:37 David TinkerDavid Tinker 9,65410 gold badges71 silver badges102 bronze badges 2- 2 stackoverflow./questions/31917889/… – weegee Commented Jun 30, 2019 at 12:41
- 1 I found that question before. I can get the button to click by calling click() or dispatching a click event to it, but that doesn't trigger the ripple effect. – David Tinker Commented Jul 1, 2019 at 15:06
2 Answers
Reset to default 6I figured it out. You have to dispatch a "mousedown" event with clientX and clientY filled in to trigger the ripple and then a "mouseup" to get rid of it.
I have a utility method in CompUtil.js:
export default {
ripple: function($el) {
let ev = new Event("mousedown")
let offset = $el.getBoundingClientRect()
ev.clientX = offset.left + offset.width/2
ev.clientY = offset.top + offset.height/2
$el.dispatchEvent(ev)
setTimeout(function() {
$el.dispatchEvent(new Event("mouseup"))
}, 300)
}
}
Then I can do:
<v-btn ref="help" ...>
CompUtil.ripple(this.$refs.help.$el)
You can do it like that
<v-btn :ripple=“your_expression”></v-btn>
You can check vuetify documentation.
https://vuetifyjs./en/directives/ripples