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

  • Home
  • SEARCH
  • 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 7490599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:41:01+00:00 2026-05-29T15:41:01+00:00

I have a simple animation: $(function () { $(.galleryButtonLeft).mousedown(function(){ $(#theGallery).animate({ marginLeft: -=300px, }, 1000

  • 0

I have a simple animation:

$(function () {
    $(".galleryButtonLeft").mousedown(function(){
        $("#theGallery").animate({ 
              marginLeft: "-=300px",
        }, 1000 );
    });
});

theGallery is just a div with position:relative.

Nothing fancy:

         <div style="position:relative">
              <img/>
         </div>

When I click my galleryButtonLeft to move it 300px to the left, the page immediately goes to the top if I have my browser unmaximized and scroll to the middle of the page where my gallery sits. I want the page to stay where it is and not jump to the top everytime the button is clicked. How do I do that?

  • 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-29T15:41:01+00:00Added an answer on May 29, 2026 at 3:41 pm

    I’ll assume that the .galleryButtonLeft element(s) is/are links with their href attribute set to a hash (#). Either return false or event.preventDefault() to cancel the default behavior of the link(s):

    $(function () {
        $(".galleryButtonLeft").mousedown(function(){
            $("#theGallery").animate({ 
                marginLeft: "-=300px"//notice I removed the trailing comma here, it'll come back to haunt you if you don't (some browsers throw errors for these)
            }, 1000 );
         }).click(false);//this returns false for any click event for the/these element(s), stopping the default behavior of the element(s)
    });
    

    Returning false inside of a jQuery event handler is the same thing as calling event.preventDefault() and event.stopPropagation().

    If you want to use event.preventDefault() instead of returning false then you have to pass-in the event object in your anonymous function (event handler):

    $(function () {
        $(".galleryButtonLeft").mousedown(function(){
            event.preventDefault();
            $("#theGallery").animate({ 
                marginLeft: "-=300px"//notice I removed the trailing comma here, it'll come back to haunt you if you don't (some browsers throw errors for these)
            }, 1000 );
        }).click(function (event) {
            event.preventDefault();
        });
    });
    

    Notice that you can call event.preventDefault() anywhere in the event handler, however returning false has to be the last thing called because it will stop the execution of the event handler.

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

Sidebar

Related Questions

I have a simple jquery animation on a div, which is inside a div,
I have a function: var myAnimation = function(){ $(.next_action).css({'bottom':-100%,left:0}).animate({'bottom':0},1000); $('.active').animate({'top':-100%},1000); } that takes two
I'm writing a simple function to animate a div (in this example called 'helpBox').
I have a simple animation on my rails site that pop's a div (with
I have a simple jQuery hover animation: jQuery(function($) { $('.category').hover(function(){ $(this).find('.banner').fadeIn(); },function(){ $(this).find('.banner').fadeOut(400); });
So I have been creating a simple animation that copies a div, and expands
I have a simple jQuery animation that moves a div to the right or
i have a very simple animation in flash CS4. My image travels from point
I have what seems to be a simple issue. I have a jquery function
It's strange. I have an animation that start when i .hover on a DIV.

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.