Click here to Skip to main content
15,886,003 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: eval() Vs setTimeout() Pin
Ankur\m/16-May-11 21:15
professionalAnkur\m/16-May-11 21:15 
AnswerRe: eval() Vs setTimeout() Pin
AspDotNetDev14-May-11 22:46
protectorAspDotNetDev14-May-11 22:46 
GeneralRe: eval() Vs setTimeout() Pin
Ali Al Omairi(Abu AlHassan)15-May-11 3:44
professionalAli Al Omairi(Abu AlHassan)15-May-11 3:44 
GeneralRe: eval() Vs setTimeout() Pin
AspDotNetDev15-May-11 6:56
protectorAspDotNetDev15-May-11 6:56 
GeneralRe: eval() Vs setTimeout() Pin
Ali Al Omairi(Abu AlHassan)15-May-11 11:04
professionalAli Al Omairi(Abu AlHassan)15-May-11 11:04 
Questionjquery wait Pin
fififlowertot5-May-11 0:48
fififlowertot5-May-11 0:48 
AnswerRe: jquery wait Pin
Not Active5-May-11 2:21
mentorNot Active5-May-11 2:21 
QuestionWhy SetTimeout doesn't work inside object? Pin
Olli Ikonen2-May-11 11:19
Olli Ikonen2-May-11 11:19 
I have a problem and i can't figure out why th setTimeout function in this object doesn't tick...
Everything else work just fine but the no ticking. I've struggled with this almost all day but
i ca'nt get the setTimeout working...

Please u wiser ones, hjälp mej...auttakaa minua...help me...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
  <script type="text/javascript" src="js/prototype.js"></script> 

<script type="application/javascript">
<!--
  
var objIdCnt = 0;
var objIdPre = "progressBar";

var ProgressBar = Class.create({
  initialize: function(Container) {
     this.Container     = Container;              // Specifies the container of img element.
    this.Id             = objIdPre + objIdCnt++;  // Specifies  unique id for each img element
    this.Type           = 1;                      // Specifies look of the progress bar: 
                                                  //  1 = Red, 2 = green, 3 = Blue in v1.0
    this.Interval       = 100;                    // Time in milliseconds between marquee animation updates.
    this.Step           =  2;                     // Specifies the marquee steps in pels when animating.   
    this.Stopped        = true;                   // Determines if animation is stopped.      
    this.Min            = 0;                      // Specifies the lower limit of the range of possible positions.       
    this.Max            = 100;                    // Specifies the upper limit of the range of possible positions.
    this.Position       = 50;                     // Specifies the current position of the progress bar. 
    this.Width          = 100;                    // Specifies the width of img element, same as the width
                                                  //  of img bitmap loaded. Updates automatically.
    this.Left           = 10;                     // Specifies the left edge of container
    this.Top            = 10;                     // Specifies the top edge of container
    this.Visible        = false;                  // Determines whether the component appears onscreen.  
    
    this.t;
    this.IncDecTotal    = 0;
    this.IncDec         = 0;
    this.ValTo          = 0;    
  },    
  create : function(position, value)
  {
    if(this.Container == null)
    {
      alert("No container.");  
    }        
    else
    {  
      var progBarImage;
      progBarImage = document.createElement('IMG');
      progBarImage.setAttribute("id", this.Id);
      progBarImage.src = "img/Frame_200x16.png";
      progBarImage.style.backgroundRepeat = "no-repeat";
      this.Width = progBarImage.width; 
      progBarImage.style.backgroundPosition = 
        -(this.Width - (this.Position - this.Min) /(this.Max - this.Min) * this.Width) + "px 0px";              
      this.Container.appendChild(progBarImage);
      this.Container.style.position = "absolute";
      this.Container.style.left = this.Left + "px";
      this.Container.style.top  = this.Top  + "px";
      this.setType(value);
      this.setPosition(position);      
    }          
  },
  hide : function()
  {
    $(this.Id).style.visibility = "hidden";  
  },
  show : function()
  {
    $(this.Id).style.visibility = "visible";  
  },
  setPosition : function(position)
  {
    this.Position = position;
    if(position > this.Max)
    {
      this.Position = this.Max;
      clearTimeout(this.t);        
    }
    if(position < this.Min)
    {
      this.Position = this.Min;
      clearTimeout(this.t);
    }
    $(this.Id).style.backgroundPosition = 
      -(this.Width - (this.Position - this.Min) / (this.Max - this.Min) * this.Width) + "px 0px";
  },
  setType : function(value)
  {
    switch(value)
    {
      case 1: $(this.Id).style.backgroundImage = "url(img/RedBar_400x16.png)";
        break;          
      case 2: $(this.Id).style.backgroundImage = "url(img/GreenBar_400x16.png)";
        break;
      case 3: $(this.Id).style.backgroundImage = "url(img/BlueBar_400x16.png)";
        break;            
    }
  },  
  doAnimate : function(value)
  {      
    if(this.Position == value)
    {
      return;
    }
    this.IncDecTotal = 0;
    this.ValTo = value;      
    this.IncDec = this.Step;
    if(this.Position > value)
    {
      this.IncDec = -this.Step;  
    }
    this.Stop = false;
    this.timedAnimate();
  },
  timedAnimate : function()
  {
//    alert("this.Id: " + this.Id + " Intv: " + this.Interval);
    this.setPosition(this.Position + this.IncDec);
    if((this.IncDec < 0) && (this.Position <= this.ValTo))
    {
      clearTimeout(this.t);
      this.Stop = true;
    }
    else if((this.IncDec > 0) && (this.Position >= this.ValTo))
    {    
      clearTimeout(this.t);
      this.Stop = true;
    }
    else
    {
      this.t = setTimeout("this.timedAnimate()", this.Interval);    
//      this.t = setTimeout(function() { this.timedAnimate(); }, this.Interval);
    }  
  },  
  sleep : function(delay)
  {
    var start = new Date().getTime();
    var cur = start
  
    while(cur - start < delay)
    {
      cur = new Date().getTime();
    }
  }
});

-->
</script>
</head>

<body>

<div id="progBar0"></div>
<br />
<input type="button" value="+5" onclick="progress0.setPosition(progress0.Position + 5);" />
<input type="button" value="-5" onclick="progress0.setPosition(progress0.Position - 5);" />

<div id="progBar1"></div>
<div id="progBar2"></div>

<script type="application/javascript">
<!--
  
var progress0 = new ProgressBar($("progBar0"));
var progress1 = new ProgressBar($("progBar1"));
var progress2 = new ProgressBar($("progBar2"));

progress0.create(25, 1);

progress1.Top = progress0.Top + 50;
progress1.create(50, 2);

//progress2.hide();

progress2.Top = progress1.Top + 50;
progress2.create(75, 3);

progress1.doAnimate(100);
-->    
</script>

</body>
</html>
</code>


If u want the images for testing, just ask...i'm glad to send them.

GBY:Olli.
Do u want to be always right or do u want to be happy...

AnswerRe: Why SetTimeout doesn't work inside object? Pin
AspDotNetDev2-May-11 11:39
protectorAspDotNetDev2-May-11 11:39 
GeneralRe: Why SetTimeout doesn't work inside object? Pin
Olli Ikonen2-May-11 13:14
Olli Ikonen2-May-11 13:14 
GeneralRe: Why SetTimeout doesn't work inside object? Pin
AspDotNetDev2-May-11 13:19
protectorAspDotNetDev2-May-11 13:19 
GeneralRe: Why SetTimeout doesn't work inside object? Pin
Olli Ikonen2-May-11 13:56
Olli Ikonen2-May-11 13:56 
Question[RESOLVED] Preserve the form status Pin
CodingLover1-May-11 20:28
CodingLover1-May-11 20:28 
AnswerRe: Preserve the form status Pin
Sunasara Imdadhusen5-May-11 3:55
professionalSunasara Imdadhusen5-May-11 3:55 
GeneralRe: Preserve the form status Pin
CodingLover5-May-11 17:58
CodingLover5-May-11 17:58 
QuestionHow can i refresh status bar information... Pin
Olli Ikonen29-Apr-11 23:42
Olli Ikonen29-Apr-11 23:42 
AnswerRe: How can i refresh status bar information... Pin
DaveAuld29-Apr-11 23:59
professionalDaveAuld29-Apr-11 23:59 
GeneralRe: How can i refresh status bar information... Pin
Olli Ikonen30-Apr-11 0:31
Olli Ikonen30-Apr-11 0:31 
GeneralRe: How can i refresh status bar information... Pin
DaveAuld30-Apr-11 0:33
professionalDaveAuld30-Apr-11 0:33 
GeneralRe: How can i refresh status bar information... Pin
Olli Ikonen30-Apr-11 1:37
Olli Ikonen30-Apr-11 1:37 
GeneralRe: How can i refresh status bar information... Pin
Luc Pattyn30-Apr-11 2:26
sitebuilderLuc Pattyn30-Apr-11 2:26 
GeneralRe: How can i refresh status bar information... Pin
DaveAuld30-Apr-11 4:05
professionalDaveAuld30-Apr-11 4:05 
GeneralRe: How can i refresh status bar information... Pin
Luc Pattyn30-Apr-11 4:48
sitebuilderLuc Pattyn30-Apr-11 4:48 
GeneralRe: How can i refresh status bar information... Pin
DaveAuld30-Apr-11 4:51
professionalDaveAuld30-Apr-11 4:51 
GeneralRe: How can i refresh status bar information... Pin
DaveAuld30-Apr-11 6:35
professionalDaveAuld30-Apr-11 6:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.