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

The Archive Base Latest Questions

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

The following blocks of code are pretty much the same… the main diffirence between

  • 0

The following blocks of code are pretty much the same… the main diffirence between them would be the left and right directional values.

I would like to reduce the following code as much as possible, by possibly reusing one block of code for both .forward & .backward. I assume that we can use variables or the html5 data-attr to store values for left and right???

Thanks again everyone!

<div class="hover-area">
    Hover area
    <div class="backward">Backward</div>
    <div class="forward">Forward</div>
</div>

<style>
    a
.hover-area {
    position: relative;
}

.forward,
.backward {
    position: absolute;
}

</style>

​

    $('.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:51:45+00:00Added an answer on June 4, 2026 at 6:51 pm

    What the heck, I played with it a little and came up with:

    $('.forward, .backward').css([$(this).is('.forward')?'right':'left'], 0).css('opacity', 0);
    $('.hover-area').on('mouseenter mouseleave', function(evt) {
        $(this).find('.forward, .backward').each(function(i,elm) {
            var direction = {};
                direction[$(elm).is('.forward') ? 'right' : 'left'] = evt.type==='mouseleave'?0:20;
            $(elm).stop()
                .animate(direction, {queue:false, duration:300, easing:'easeOutCubic'})
                .animate({opacity: evt.type==='mouseleave'?0:0.95}, {queue:false, duration:400, easing:'easeOutCubic'});
        });
    });​
    

    DEMONSTRATION

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

Sidebar

Related Questions

I wrote the following test code, even though I was pretty sure what would
I have the following two code blocks. Code block 1 var checkboxes = $(div.c1
I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code
Pretty much everyone that writes about the UISplitView on the iPad uses the following
You'll appreciate the following two syntactic sugars: lock(obj) { //Code } same as: Monitor.Enter(obj)
The following code is pretty self-explanatory and my question is very simple : Why
The following code blocks on my system. Why? System.out.println( Pattern.compile( ^((?:[^'\][^'\]*|\[^\]*\|'[^']*')*)/\\*.*?\\*/(.*)$, Pattern.MULTILINE | Pattern.DOTALL
I have been told that there is a performance difference between the following code
Consider the following block of code: class CheckStore { private String displayText; private boolean
i have the following block of code: $(#contact_container form, #contact_details form).live( submit, function(event) {

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.