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 8985389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:19:09+00:00 2026-06-15T21:19:09+00:00

I ran across this snippet of code and have used it as a reference

  • 0

I ran across this snippet of code and have “used” it as a reference for developing my own specific toggle function.

Raphael.js – if / else statement not toggling on click

http://jsfiddle.net/YLrzk/1/

I would like to apply an animation to the stroke-width per say when it is increased on click. I can’t seem to figure out how to add this animation in alongside the toggle function.

I figured this would be applied around the variables StrON and StrOFF so I have tried things such as:

 var strOff = function() {
            this.animate({ 'stroke-width': '1' }, 100);

        }; 

    var strOn  = function() {
            this.animate({ 'stroke-width': '5' }, 100);

        }; 

and even just:

var strOff = 
        this.animate({ 'stroke-width': '1' }, 100);



var strOn  = 
        this.animate({ 'stroke-width': '5' }, 100);

Sorry about the lazy syntax If I missed anything on the two examples of what I’ve tried. Thanks for any help.

  • 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-06-15T21:19:10+00:00Added an answer on June 15, 2026 at 9:19 pm

    Neither of these will work because strOn and strOff are not the right data type — they must be an object containing attributes for the selected and deselected states of a given rectangle. This represents a fundamental misunderstanding of what animate does: it is essentially an asynchronous version of attr.

    You could solve your problem by simply restoring strOn and strOff to their original state and then calling this in the click handler for a given rectangle:

    box1.animate( strOn, 100 );
    box2.animate( strOff, 100 );
    box3.animate( strOff, 100 );
    

    This still leaves you with a complexity issue. If you want to add a fourth or fifth rectangle, you will quickly drown in conditional logic. This sort of state information should, in my opinion, almost never be implemented like this. Instead, I recommend doing this:

    Use a single, generic click handler.

    var genericClickHandler = function()
    {
        //  First step: find and deselect the currently "active" rectangle
        paper.forEach( function( el )
            {
                if ( el.data('box-sel' ) == 1 )
                {
                    el.animate( strOff, 100 ).data('box-sel', 0 );
                    return false; // stops iteration
                }
            } );
        this.animate( strOn, 100 ).data( 'box-sel', 1 );
    }
    

    This will iterate through all elements in the paper — if one of them is marked as “active,” it will be animated back into its inactive state.

    Use data to keep track of the selected rectangle:

    paper.rect( x1, y1, w1, h1 ).attr( {} ).data( 'box-sel', 0 ).click( genericClickHandler );    // note that we're setting data to indicate that this rectangle isn't "active"
    paper.rect( x2, y2, w2, h2 ).attr( {} ).data( 'box-sel', 0 ).click( genericClickHandler );
    // ... as many rectangles as you like
    paper.rect( xN, yN, wN, hN ).attr( {} ).data( 'box-sel', 0 ).click( genericClickHandler );
    

    Using this approach, there’s no need to keep track of individual rectangles — only whether or not a given rectangle is selected or not.

    Here’s an example supporting many rectangles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Function Annotations: PEP-3107 I ran across a snippet of code demonstrating Python3's function annotations.
While reading Programming Ruby , I ran across this code snippet: while gets num1,
I ran across the following snippet of code. Names have been changed to protect
I just ran across this snippet of code for swapping the values of two
I'm doing some code maintenance at work, and I ran across this little snippet...
I ran across this snippet in an internal web site, but I'm having trouble
I ran across this chunk of code (modified) in our application, and am confused
A situation I ran across this week: we have a jQuery Ajax call that
I just ran across this javascript snippet: myArray.length--; What does it do exactly?
I ran across this pattern in the code of a library I'm using. It

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.