Jump to content
Search Community

storing URL's for several SVG buttons with tweenMax rollovers

Liam@II test
Moderator Tag

Go to solution Solved by GreenSock,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi

 

im lookin for some help. i guess this is a JS question and not strictly a GSAP question but hopefully someone can help.

 


var buttons = document.getElementsByClassName("click");

var myFunction1 = function() {
 TweenMax.to(this, 0.8, {scale:1.1, ease: Elastic.easeOut.config(1, 0.2)});
};

var myFunction2 = function() {
 TweenMax.to(this, 1, {scale:1, ease: Elastic.easeOut.config(1, 0.2)});
};

var myFunction3 = function(url) {
  var win = window.open(url, '_blank');
};


for (var i = 0; i < buttons.length; i++) {
    buttons[i].addEventListener('mouseover', myFunction1, false);
    buttons[i].addEventListener('mouseout', myFunction2, false);
    buttons[i].addEventListener('click', myFunction3, false);
}

here i create an array (is it actually an array?) or buttons based on the class of .click and i assign 3 event listeners to eacb button.  

id like to pass in a URL for each button to myFunction3.

 

where would i store these URLs?

would i need to lose the code i have and create new code where i create a button object?

 

thanks and i appreciate any help you can offer

 

See the Pen e5271590a2b526a935a597ce988f36e8 by Liamii (@Liamii) on CodePen

Link to comment
Share on other sites

  • Solution

Technically I think it's a NodeList (not an Array) that's returned by getElementsByClassName(), but it acts a lot like an Array. 

 

You certainly could handle this all directly in JavaScript, but if it were me I'd put the URL data directly in the HTML so that it's very clearly associated with the nodes there (easier to map mentally, and avoids potential errors due to the order things are returned by your selector). So I'd simply add a data-url attribute to each one like:

<g id="cashRegister_Icon" class="icon click" data-url="http://greensock.com">

and then access it in your handler like:

this.getAttribute("data-url")

Does that help?

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...