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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:43:22+00:00 2026-06-13T15:43:22+00:00

I have been dabling with a javascript image panner to which I have hacked

  • 0

I have been dabling with a javascript image panner to which I have hacked and shredded together from code on here… I have now abandoned this for a simpler method but need advice on how to do a couple of things.

I have this code for left and right buttons.

<div id="wrap">

<div class="entrance-hall pan-image">


</div>
</div>

<input type="button" value="Move Left" class="nav-left" onclick="pan_animate('-=20%')"  />
<input type="button" value="Move Right" class="nav-right"  onclick="pan_animate('+=20%')" />

and this for the javascript.

function pan_animate(px) {
$('.pan-image').animate({
    'marginLeft' : px
});
}

It pans an image left or right 20% within the wrapping div however I want to…

  1. make it scroll smoothly rather than in increments of a percentage
  2. stop going past the edge of the left and right container
  3. start at the center of the image.

Not asking for much eh? Hope this makes sense and someone can help!

Cheers.

css added

#wrap {
margin-bottom:60px;
border:4px solid white;
overflow:hidden;
}


 .pan-image {
position:relative;
width:2106px; 
height:395px;
left:50%;
margin-left:-1053px;
 }

 /* -- ===entrance hall=== -- */

.entrance-hall { 
background:url(/staging/kennawayhouse.org.uk/images/1-entrance-hall.jpg);
}
  • 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-13T15:43:23+00:00Added an answer on June 13, 2026 at 3:43 pm
    • Make it scroll smoothly rather than in increments of a percentage

    One way to achieve this is simply using easing functions. From the jQuery animate api:

    Easing

    The remaining parameter of .animate() is a string naming an easing function to use. An easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear. More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.

    Your code could be then, changed to:

    function pan_animate(px) {
        $('.pan-image').animate({'marginLeft' : px}, 'linear'); // Swing and Linear comes in jQuery, but swing is the default value.
    }
    

    And some smooth will be perceived.

    • Stop going past the edge of the left and right container

    This one will need some css hack, but position:absolute;left:5x;top:5px may solve your problem about the inner element. If you want an answer more accurate than may, you can post your css code.

    EDIT

    Based on your css code, I’ve achieved a function that alert if your margin has trespassed the limit of it’s parent when moving:

    function pan_animate(px) {
        
        $marginLeftCss = $(".pan-image").css("marginLeft").replace(/[^-\d\.]/g, '');
        $n = px.replace(/[^-\d\.]/g, '');
        $x = (px.indexOf("-")==0) ? 1 - ($n/100):($n/100);
        
        $marginLeft = $marginLeftCss * $x;
        
        $width = $(".pan-image").width();
        $width += $(".pan-image").parent().width();
        
        if($marginLeft > - $width && $marginLeft < $width) //4212 = width*2
            $('.pan-image').animate({'marginLeft' : px}, 'linear');
        else
            alert("pan image reached it\'s end "  + $marginLeft);
    }
    

    You can check it a fiddle: http://jsfiddle.net/brunovieira/3wHn3/7/

    • Start at the center of the image.

    In order to center your $(".pan-image") elements you can use two approaches, the css one: position:relative;margin-left:auto;margin-right:auto, or, in case position relative is not an option, you can center your element using jQuery like:

    $parentHeight = $(".pan-image").parent().height();
    $parentWidth = $(".pan-image").parent().width();
    
    $panImageHeight = $(".pan-image").height();
    $panImageWidth = $(".pan-image").width();
    
    $(".pan-image").css('position','absolute','top',($parentHeight - $panImageHeight)/2 + 'px', 'left',($parentWidth - $panImageWidth)/2+'px');
    

    Again, depending of your coding, the conditions above answered may not work.

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

Sidebar

Related Questions

have been able to output images from BLOB, however I am now wanting to
have been trying couple of hours now to make my iphone app universal. The
Have been looking at the MVC storefront and see that IQueryable is returned from
Have been following this fabulous tutorial . Being new to Javascript and functional programming,
Have been working on a Tower Defense game for iOS for some time now.
I have been using the examples from this site ( http://dojotoolkit.org/documentation/tutorials/1.6/datagrid/ ) to render
I have been debugging on an HTC Desire for which I had the ADB
I have been dabbling in game development as a hobby for a while now,
Have been trying to fix this problem I have here. Basically I have a
and thanks in advance for any help. I have been dabbling in this code

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.