Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Decrease div width from 100% to 0% in ten seconds

Posted on 2013-06-17
Medium Priority
Last Modified: 2013-06-19

I need to make a time indicated decrease bar. The bar's width must decrease from 100% to 0% width in 10 seconds.

How could i do that?

Question by:peps03
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 54

Accepted Solution

Scott Fell,  EE MVE earned 1500 total points
ID: 39254790
Working sample http://jsbin.com/obeyob/1/edit
<!DOCTYPE html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<button id="go">&raquo; Start</button>
<div id="container"> 
    <div id="bar"></div>

    width: "0%",
  }, 10000 );

Open in new window


Author Comment

ID: 39256229

i put the code in this function:

			$(function() {
				refreshContent(); // Call refreshContent immediately
			function refreshContent()
			        $(".bar").animate({width: "0",}, 10000 );	
				$.post('testemonial-content.php',{}, function(resp) {

Open in new window

and it sort of works as expected, for the first 2 rounds. after the content has switched twice, the bar doesn't run anymore.

Why does it stop running?
LVL 53

Expert Comment

ID: 39256597
In modern browsers you do it with the CSS:

.bar {
.barActive {
                      transition:width 10s ease-out;
Then all you need is an event to change the className from 'bar' to 'barActive'.

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39256827
I like that ease of use without js.  I have not fully embraced it yet because I enjoy making things overly complex for myself and get satisfaction from making it work.

Just add, "-webkit-transition:width 10s ease-out;" so it works with safari.  

If you are looking to do some type of timer that starts when an action happens like answering a test question, you will need to use javascript/jquery.
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39256839
>Why does it stop running?
Will you please edit the jsbin I created with just the important code and lets take a look.

Even better, please post the link to your sample page.
LVL 19

Assisted Solution

by:Albert Van Halen
Albert Van Halen earned 500 total points
ID: 39257545
The 10 second interval occurs just a bit earlier than the animation is complete.
In order to have it working you have to stop the animation using the stop method.

Open in new window


Author Closing Comment

ID: 39258645
@padas, thanks for the code, great!

@AlbertVanHalen, thanks!! This works!!
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39258731
Thanks for the points

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question