Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7492599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:28:37+00:00 2026-05-29T16:28:37+00:00

I am fairly new to various design structures and OOP. what i am trying

  • 0

I am fairly new to various design structures and OOP. what i am trying to do is to make a function which will generate a menu icon that animates during mouseover/mouseout. Therefore, I will just call the function and input the (x,y, width, height, etc….) and allow it to generate the menu icon with a few animation features. I am trying to use the “this” keyword to somewhat have a generic model to help generate multiple menus more easily. but I can’t apply the “this” keyword into the function. Please provide me with some advice on what I should do. Thanks in advanced.

function button(x, y, width, height, text1, text2) {
paperWidth = width +10;
paperHeight = height + 10;
this.paper = Raphael(x, y, paperWidth, paperHeight); // sets the paper dimension with x and y coordinates
// menu box variables
this.rectFrontX = x+20; this.rectFrontY = y+20; this.rectFrontWidth = 70; this.rectFrontHeight = 45;
this.rectBackX = x+10; this.rectBackY = y+10; this.rectBackWidth = 95; this.rectBackHeight = 67;
// text variables
this.textLine1X = x+45+10; this.textLine1Y = y+25+10; 
this.textLine2X = x+45+10, this.textLine2Y = y+35+15;

// menu box variables
rectFrontX = x+20; rectFrontY = y+20; rectFrontWidth = 70; rectFrontHeight = 45;
rectBackX = x+10; rectBackY = y+10; rectBackWidth = 95; rectBackHeight = 67;
// text variables
textLine1X = x+45+10; textLine1Y = y+25+10; 
textLine2X = x+45+10, textLine2Y = y+35+15;

//testing variables only, not using
currentX = x;
currentY= y;
this.x = x; this.y = y;

// initialize menu variables
var backBox = this.paper.rect(this.rectBackX, this.rectBackY, this.rectBackWidth, this.rectBackHeight).attr({fill: "white", "cursor": "pointer"});
var midBox = this.paper.rect(this.rectFrontX, this.rectFrontY, this.rectFrontWidth, this.rectFrontHeight).attr({fill: "#CCC", opacity: 0.0, "cursor": "pointer"});
var frontBox = this.paper.rect(this.rectFrontX, this.rectFrontY, this.rectFrontWidth, this.rectFrontHeight).attr({fill: "gray", opacity: 1.0, "cursor": "pointer"}); //dark grey menu box
var backLineTop = this.paper.text(this.textLine1X, this.textLine1Y, text1).attr({"font-size":14, "fill": "#fff", "cursor": "pointer"});
var backLineBottom = this.paper.text(this.textLine2X, this.textLine2Y, text2).attr({"font-size":14, "fill": "#fff", "cursor": "pointer"});
var frontLineTop = this.paper.text(this.textLine1X, this.textLine1Y, text1).attr({"font-size":14, "fill": "#fff", "opacity": 0.0,  "cursor": "pointer"});
var frontLineBottom = this.paper.text(this.textLine2X, this.textLine2Y, text2).attr({"font-size":14, "fill": "#fff", "opacity": 0.0,  "cursor": "pointer"});
var menuOverlay = this.paper.rect(this.rectBackX, this.rectBackY, this.rectBackWidth, this.rectBackHeight).attr({"fill": "red", "cursor": "pointer", "opacity": 0.3}); // overlays menu box for 




menuOverlay.mouseover(function() {
// set initial property values before animation
    frontBox.attr({"x": rectFrontX, "y": rectFrontY});
    midBox.attr({"x": x, "y": y});
    frontLineTop.attr({"x": textLine1X-20, "y": textLine1Y-20, "font-size": 6, opacity: 1.0});
    frontLineBottom.attr({"x": textLine2X-20, "y": textLine2Y-20, "font-size": 6, opacity: 1.0});
    backLineTop.attr({"x": textLine1X, "y": textLine1Y-20, "font-size": 6, opacity: 1.0});
    backLineBottom.attr({"x": textLine2X, "y": textLine2Y-20, "font-size": 6, opacity: 1.0});

    // animation values
    frontBox.animate({"x": currentX+40, "y": currentY+30,  "width": rectFrontWidth, "height": rectFrontHeight,"opacity": 0.0}, 1000, "linear"); // frontbox fading away from screen
    midBox.animate({"x": currentX+20, "y": currentY+20, "width": rectFrontWidth, "height": rectFrontHeight, "opacity": 1.0, "fill": "#CCC"}, 1500, "bounce"); // midbox drops in from the top left
    frontLineTop.animate({"font-size": 14, "x": textLine1X, "y": textLine1Y, "opacity": 1.0, "fill": "black"}, 500, "linear"); // animate text on mouse over adding 20 to Y and  10 to X
    frontLineBottom.animate({"font-size": 14, "x": textLine2X, "y": textLine2Y,  "opacity": 1.0, "fill": "black"}, 500, "linear"); // animate text on mouse over adding 20 to Y and 10 X
    backLineTop.animate({"font-size": 6, "x": textLine1X+35, "y": textLine1Y+65,  "opacity": 0.0, "fill": "black"}, 500, "linear"); // animate text on mouse over adding 20 to Y and  10 to X
    backLineBottom.animate({"font-size": 6, "x": textLine1X+35, "y": textLine1Y+35,  "opacity": 0.0, "fill": "black"}, 500, "linear"); // animate text on mouse over adding 20 to Y and 10 X
});
menuOverlay.mouseout(function() {
// set initial property values before animation
    frontBox.attr({"x": rectFrontX, "y": rectFrontY-20, "opacity": 1.0 });
    midBox.attr({"x": rectFrontX+0, "y": rectFrontY+0});
    backLineTop.attr({"x": textLine1X, "y": textLine1Y-20, "font-size": 6, opacity: 1.0, "fill": "white"});
    backLineBottom.attr({"x": textLine2X, "y": textLine2Y-20, "font-size": 6, opacity: 1.0, "fill": "white"});

    // animation values
    midBox.animate({"x": rectFrontX+40, "y": rectFrontY+20, "width": rectFrontWidth, "height": rectFrontHeight, "opacity": 0.0 }, 1500, "bounce");
    frontBox.animate({"x": rectFrontX, "y": rectFrontY,  "width": rectFrontWidth, "height": rectFrontHeight,"opacity": 1.0, "fill": "gray"}, 1500, "bounce"); // frontbox fading away from screen
    backLineTop.animate({"font-size": 14, "x": textLine1X, "y": textLine1Y, "opacity": 1.0, "fill": "white"}, 500, "linear"); // animate text on mouse over adding 20 to Y and  10 to X
    backLineBottom.animate({"font-size": 14, "x": textLine2X, "y": textLine2Y,  "opacity": 1.0, "fill": "white"}, 500, "linear"); // animate text on mouse over adding 20 to Y and 10 X
    frontLineTop.animate({"font-size": 14, "x": textLine1X+20, "y": textLine1Y+15, "opacity": 0.0, "fill": "white"}, 500, "linear"); // animate text on mouse over adding 20 to Y and  10 to X
    frontLineBottom.animate({"font-size": 14, "x": textLine2X+20, "y": textLine2Y+15, "opacity": 0.0, "fill": "white"}, 500, "linear"); // animate text on mouse over adding 20 to Y and 10 X
});
}

// I will then call the function to create the menu icon
var testMenuIcon = new button(10, 10, 120,  120, "menu text line 1", "menu text line 2");

Now the problem is that when I try to use the “this” keyword within the mouseover function, it is not able to get the “this” variable in there, so if I create multiple menu icon the x,y values among 2 or more menu icon gets all mixed up because the same values seems to be used on different menu icons. Please advise on what is the best method to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:28:39+00:00Added an answer on May 29, 2026 at 4:28 pm

    You cannot access this of menu instance inside mouseover , because this now means a different scope. so to fix this

    function button(x, y, width, height, text1, text2) {
      //Your code
    
      //based on your logic use
      var self = this; 
      //or 
      var self = menuOverlay; 
    
      menuOverlay.mouseover(function() {
         //You can use self to access the menu now (self.whatever)
      }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I fairly new to JQuery and perhaps trying to achieve something that might be
Ok I will start by saying I'm fairly new to programing android applications. That
Fairly new to Objective C and trying to work within Storyboards given it's the
I am fairly new to stored procedures. I naively thought that I could build
I'm fairly new to ASP.NET and trying to learn how things are done. I
Let me state up front, that sockets programming is fairly new to me. Also,
I'm fairly new to C# programming but I'll explain what it is I'm trying
fairly new Android developer here. I've come across a strange problem that I'm not
I am fairly new at using the ASP.NET MVC framework and was hoping that
As someone who is fairly new to iPhone development, I've been trying to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.