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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:21:01+00:00 2026-06-04T18:21:01+00:00

I have two animations which are practically identical… the difference between them is left

  • 0

I have two animations which are practically identical… the difference between them is “left vs right” positioning. I would like to reuse the first block of code for both .forward and .backward… I’m guessing this could be done with the use of a HTML 5 data- attributes or maybe variables, but I’m not sure how to go about that.

Please advise this noob… thanks!

      .hover-area { position:relative; width:100%; height:50px; }
      .backward, .forward { position:absolute; }
      .backward{ left:0px; }
      .forward { right:0px; }​


      <div class="hover-area">
          Hover Area
          <div class="backward">Previous</div>
          <div class="forward">Next</div>
      </div>
        $('.forward').css({opacity:0, right:0});
        $('.hover-area').hover(function() {
            $(this).find('.forward').stop()
                .animate({right:20}, {queue:false, duration:300, easing:'easeOutCubic'})
                .animate({opacity:'0.95'}, {queue:false, duration:400, easing:'easeOutCubic'});
        },function() {
            $(this).find('.forward').stop()
                .animate({right:0}, {queue:false, duration:550, easing:'easeOutSine'})
                .animate({opacity:'0'}, {queue:false, duration:300, easing:'easeOutSine'});
        });




        $('.backward').css({opacity:0, left:0});
        $('.hover-area').hover(function() {
            $(this).find('.backward').stop()
                .animate({left:20}, {queue:false, duration:300, easing:'easeOutCubic'})
                .animate({opacity:'0.95'}, {queue:false, duration:400, easing:'easeOutCubic'});
        },function() {
            $(this).find('.backward').stop()
                .animate({left:0}, {queue:false, duration:550, easing:'easeOutSine'})
                .animate({opacity:'0'}, {queue:false, duration:300, easing:'easeOutSine'});
        });
  • 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-04T18:21:02+00:00Added an answer on June 4, 2026 at 6:21 pm

    The easiest (and most versatile) method may be to use HTML5 data-attributes to store the start/stop animation states as JSON data. Example:

    http://jsfiddle.net/ChrisPebble/LFsVr/

    HTML

    <div class="hover-area" data-animate-on='{"right":"20"}' data-animate-off='{"right":"0"}'>hover over me
        <div class="slider">I move to the right</div>
    </div>
    
    <div class="hover-area" data-animate-on='{"left":"20"}' data-animate-off='{"left":"0"}'>hover over me
        <div class="slider">I move to the left</div>
    </div>
    

    jQuery

    $('.slider').css({opacity:0, right:0});
    $('.hover-area').hover(function() {
        var animationOn = jQuery.parseJSON(($(this).attr("data-animate-on")));
        $(this).find('.slider').stop()
            .animate(animationOn, {queue:false, duration:300, easing:'easeOutCubic'})
            .animate({opacity:'0.95'}, {queue:false, duration:400, easing:'easeOutCubic'});
    },function() {
        var animationOff = jQuery.parseJSON(($(this).attr("data-animate-off")));
        $(this).find('.slider').stop()
            .animate(animationOff, {queue:false, duration:550, easing:'easeOutSine'})
            .animate({opacity:'0'}, {queue:false, duration:300, easing:'easeOutSine'});
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a FrameLayout in which I have placed two identical TextViews. I want
I have two views that I would like to fade in and out. I
I have created two view controllers in which there is UIImage animations.Its crashing frequently
Hello I have problem to put together animations of two separate objects to second
I have a small problem with UINavigationController animation between two view. My application build
WP 7.5 app. I have two Storyboard animations - one on image and another
I have a UIView called activityView , which contains two subviews activityIndicator and cancelOperationsButton
I have two divs which I want to animate: <div id="character"> <div id="sprite"></div> </div>
I'd like to have an animated character on the page, with different animations for
I have two UIViewControllers which I sometimes need to show at the same time.

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.