This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Dave Marchuk
Posted Jan 15 - Read on Facebook

Is there a way to use the "this" keyword with framerjs? My situation is that I have an element that gets triggered via a right click (contextmenu). However with framerjs, to trigger an event you have to use:

element.on("contextmenu"), function(event) { do some stuff });

to make the action recognized, thus removing the possibility of using "this" as the reference is lost (from what I understand).

I've tried using element.contextmenu = function(), but that didn't work, neither did element.addEventListener... I was getting js errors about no "reference to the object", "no method of that name" or the function wasn't even triggering (tested that with console.log).

My goal is to create a re-usable function that I can attach to a number of elements that will use the same "do some stuff" code, and then use an if statement to see which element "this" is and do some more stuff.

Anyone have any advice on how I could accomplish this? Thanks for any help!

4 Comments

Petr Bela

i think event.target should give you the clicked element

Koen Bok

or do something like this:

function setUpReusableEffect(view) {
view.on("click", function() {
view.animate({...})
})
}

Dave Marchuk

Thanks guys! I will give it a shot. I am thinking I will need both of your solutions :)

Dave Marchuk

Worked like a charm! Now I just need to refactor about 1000 lines of code LOL

Read the entire post on Facebook