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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:37:08+00:00 2026-06-03T14:37:08+00:00

I have a problem that I need to sort out in javascript I believe,

  • 0

I have a problem that I need to sort out in javascript I believe, but dont know how to begin with it, so hopefully someone from the javascript community may be able to help please.

Basically, the following code allows me to load 10 images into a slideshow carousel.
However, these images are either 600px x 400px Portrait or 400px x 600 Landscape. The problem I have is that the Landscape images
are vertically aligned to the top of the container.

I have managed to get around this by creating two classes in my CSS file image-P & image-L

image-L has a “padding-top:100px ” which successfully vertially aligns the landscape images in the centre.

What I’d like to do is for the code to check which images are landscape and then create

return '<img src="Images/' + item.url + '" class="image-L" alt="" />';

and anything else use

return '<img src="Images/' + item.url + '" class="image-P" alt="" />';

many thanks in advance.

Cheers Rob.

<script type="text/javascript">

    var mycarousel_itemList = [
        { url: "Image1.jpg" },
        { url: "Image2.jpg" },
        { url: "Image3.jpg" },
        { url: "Image4.jpg" },
        { url: "Image5.jpg" },
        { url: "Image6.jpg" },
        { url: "Image7.jpg" },
        { url: "Image8.jpg" },
        { url: "Image9.jpg" },
        { url: "Image10.jpg" }
    ];

    function mycarousel_itemLoadCallback(carousel, state) {
        for (var i = carousel.first; i <= carousel.last; i++) {
            if (carousel.has(i)) {
                continue;
            }

            if (i > mycarousel_itemList.length) {
                break;
            }

            carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i - 1]));
        }
    };

    /**
    * Item html creation helper.
    */
    function mycarousel_getItemHTML(item) {
        return '<img src="Images/' + item.url + '" class="image-L" alt="" />';
    };

    jQuery(document).ready(function () {
        jQuery('#mycarousel').jcarousel({
            size: mycarousel_itemList.length,
            itemLoadCallback: { onBeforeAnimation: mycarousel_itemLoadCallback }
        });
    });

  • 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-03T14:37:09+00:00Added an answer on June 3, 2026 at 2:37 pm

    You could try loading the image into JavaScript [1] with the Image class [2] and check the height/width of the image itself to determine which class to apply, but this would slow things down if you did it at load time. (I don’t know if the browser would cache the file or not for when you went to display it later).

    It seems like it’d be better to wait and apply the style after the image has been added to the document/displayed.

    You could probably use jQuery to get the height of the (browser) view and the height of the image then absolutely position the image to be centered. (That’d be more flexible if you wanted to use different image sizes later).

    1. http://www.techrepublic.com/article/preloading-and-the-javascript-image-object/5214317
    2. http://www.w3schools.com/jsref/dom_obj_image.asp
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use something like get_or_create() but the problem is that I have
I have an interesting SQL problem that I need help with. Here is the
The problem is this: I have multiple competing threads (100+) that need to access
I have a problem with reflection. I need to find the type that instantiates
i have very simple problem. I need to create model, that represent element of
I have the problem that add_custom_command is always out of date and therefore runs
I have a problem that I have been thinking about, but I can't really
Just need help as I have been trying sort this out for ages now.
I have a little dilemma that maybe you can help me sort out. I've
In a couple of scripts that I use I have problem that is intermittent.

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.