# Hold on element to toggle class

**URL:** <https://forum.ionicframework.com/t/hold-on-element-to-toggle-class/103766>\
**Category:** ionic-v3\
**Created:** [August 30, 2017, 6:57pm UTC](https://forum.ionicframework.com/t/hold-on-element-to-toggle-class/103766 "2017-08-30T18:57:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tumain](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tumain/32/107546_2.png) [@tumain](https://forum.ionicframework.com/u/tumain)\
**Post date:** [August 30, 2017, 6:57pm UTC](https://forum.ionicframework.com/t/hold-on-element-to-toggle-class/103766/1 "2017-08-30T18:57:42Z")

</div>

Hi - I need to show images blurred. If a user holds down on the image then the image unblurs until they move off. This is done by toggling a class on the image. I have attempted to use a custom directive to no avail. It doesn’t work if you drag off the image, because the release isn’t detected.

```auto
import { Directive, ElementRef, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
import { Gesture } from "ionic-angular/gestures/gesture";

@Directive({
    selector: '[long-press]'
})
export class PressDirective implements OnInit, OnDestroy {
    el: HTMLElement;
    pressGesture: Gesture;
    @Output('long-press') onPressRelease: EventEmitter<any> = new EventEmitter();
    @Output('long-press-up') onPressUp: EventEmitter<any> = new EventEmitter();

    constructor(el: ElementRef) {
        this.el = el.nativeElement;
    }

    ngOnInit() {
        this.pressGesture = new Gesture(this.el);
        this.pressGesture.listen();
        this.pressGesture.on('press', (event) => {
            this.onPressRelease.emit('released');
        });
        this.pressGesture.on('pressup', (event) => {
            this.onPressUp.emit(event);
        });
    }

    ngOnDestroy() {
        this.pressGesture.destroy();
    }
}

```

That is the current directive - any advice is greatly appreciated.
