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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:38:55+00:00 2026-05-30T05:38:55+00:00

I am a bit stuck. I am creating a rotating background image with jquery

  • 0

I am a bit stuck. I am creating a rotating background image with jquery and css. I resize the image width according to the browser size, but I do not want to change the height because it distorts the picture. So I want to do a simple math equation to make the image vertically centered on the screen. For example: The image has an original size of 1600px and it resizes to 1200px, I need to get the height of the resized image. I have tried this with jquery simple: $(“#img1”).height(); but it returns the value 0. Here is my jquery, html and css:

HTML

<div id="div2"><img src="images/1.jpg" class="bg" id="img1" /></div>
<div id="div3"><img src="images/1-blur.jpg" class="bg"/></div>
<div id="content">Body Content goes here!!</div>

<script>
var iheight = $("#img1").height();
$("#content").append(iheight);
</script>

CSS
body{
padding: 0;
margin: 0;
position: relative;
overflow: hidden;
}
.bg {
width: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
#content{
position: relative;
z-index: 999;
}

And Jquery to rotate images:

$(window).load(function(){
function startfade(){

$("#div3").fadeIn(3000, function(){
    $(this).delay(2000).fadeOut(2000);
    $("#div2").fadeIn(3000, function(){
        $(this).delay(2000).fadeOut(2000);
});
});

}
setInterval(function() {
      startfade();
}, 6000);


startfade();


});

Any help on how to get the actual height of the image would be awesome! Thank you so much!

  • 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-30T05:38:57+00:00Added an answer on May 30, 2026 at 5:38 am

    Try to call height when image is loaded (and you should always enclose your code in $(function() {}); so your code is invoked when DOM is ready)

    $(function() {
       $('#img1').load(function() {
           $("#content").append($(this).height());
       });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a tableless Rails model, and am a bit stuck on how I
I'm a bit stuck with my code: def setVenueImage(img): img = images.Image(img.read()) x, y
I'm working on learning Objective-C/Coaoa, but I've seem to have gotten a bit stuck
im creating a game right now and im a bit stuck on how to
i'm currently creating a database program in java and i am a bit stuck
Sorry, this is a bit of code, but there's not much to cut out
Okay, this is a bit abstract, but here goes: I'm creating a website and
bit stuck try to achieve something in Jquery and wondered if anyone can assist..
Hey I am a bit stuck at the moment, I am creating a forum,
I'm a bit stuck on this. Basically I want to do something like the

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.