Showing posts with label background. Show all posts
Showing posts with label background. Show all posts

Sunday, May 15, 2011

How to make your background image as carousel using CSS and jQuery

This post will teach you how to set your background as carousel of images using CSS and jQuery.

To do this, just follow the 3 simple steps below.

1. First, you should have the list of images for your site's background.

2. Set an id for your <body> tag, let say id="body" as stated below.

<html>
<head>
</head>
<body id="body">
</body>
</html>

3. Create a javascript that changes the background-image property of the body tag using jquery and set it in a loop using setTimeout().

<script type="text/javascript">
        function carousel_bg(id) {
                var bgimgs = [ '1920x625_Sonata_homepage_image.jpg', '1920x625_Equus_homepage_image.jpg', '5_home_hero_1920x625_CF_background.jpg' ]; // add images here..
                var img = bgimgs[id];
                var cnt = 3; // change this number when adding images..

                $('#body').css("background-image", "url(http://www.pitstopmotors.com.ph/images/"+img+")");

                id = id + 1;
                if (id==cnt) id = 0;

                setTimeout("carousel_bg("+id+")", 10000);
        }

        $(document).ready(function() {
                carousel_bg(0);     
        });
</script>

You can still add images by adding the image filename on the array "bgimgs" and change the variable "cnt" to add images as part of the loop.. and that's it.

To get the complete code, please see below.

<html>
<head>
<title>Hotshots Carousel Background</title>

<script type="text/javascript" src="http://www.pitstopmotors.com.ph/js/jquery-1.4.2.js"></script>
<script type="text/javascript">
        function carousel_bg(id) {
                var bgimgs = [ '1920x625_Sonata_homepage_image.jpg', '1920x625_Equus_homepage_image.jpg', '5_home_hero_1920x625_CF_background.jpg' ]; // add images here..
                var img = bgimgs[id];
                var cnt = 3; // change this number when adding images..

                $('#body').css("background-image", "url(http://www.pitstopmotors.com.ph/images/"+img+")");

                id = id + 1;
                if (id==cnt) id = 0;

                setTimeout("carousel_bg("+id+")", 10000);
        }

        $(document).ready(function() {
                carousel_bg(0);     
        });
</script>
</head>
<body id="body">
</body>
</html>

Leadership 101


  • Leadership demands sacrifices for the near-term to receive lasting benefits. the longer we wait to make sacrifices, the harder they become. Successful people make important decisions early in their life, then manage those decisions the rest of their lives.
  • Growth does not happen by chance. If you want to be sure to grow, you need a plan something strategic, specific, and scheduled. it's a discipline that would need incredible determination from us.
  • Success comes by going the extra mile, working the extra hours, and investing the extra time. The same is true for us. If we want to get to excel in any segment of life, a little extra effort can help. Our efforts can go a long way if we only work a little smarter, listen a little better, push a little harder, and persevere a little longer.
  • Making a difference in your work is not about productivity; it's about people. When you focus on others and connect with them, you can work together to accomplish great things.
  • Envision a goal you'd like to reach. Make it big enough to scare you a little. Now write down a plan for moving toward it. Create mini-goals within the big goal, to set yourself up for continual progress. And include some risks, too. Set yourself up for success.
  • Leaders build margins, not image. A leader may be forced to take unpopular stands for the good of the company. Popularity isn't bad, but decisions made solely on the basis of popular opinion can be devastating. So take courage and make the right though sometimes painful choices.