<?xml version="1.0"?>
<rss version="2.0">
 <channel>
  <title>confused about moving a div block | WPDFD.com Forums</title>
  <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/</link>
  <description>A Scripting forum thread at WPDFD.com</description>
  <language>en-us</language>
  <pubDate>07/20/04, 202 48 2004 2004:%i:1090356527 16:48:47</pubDate>
  <lastBuildDate>06/07/13, 158 32 2013 2013:%i:1370593958 04:32:38</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>NineLabs Framework Feed Generator</generator>
  <managingEditor>sitemaster@wpdfd.com</managingEditor>
  <webMaster>sitemaster@wpdfd.com</webMaster>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1109</link>
    <description><![CDATA[I attempted to use some javascript from the &quot;Dynamic CSS animation&quot; article but it broke when I made a change. Instead of &quot;thebox.style.backgroundPosition&quot; in the script I used &quot;thebox.style.left&quot; and made &quot;x=x-steps&quot; into &quot;x=x+steps&quot; in the belief that it would move the div block in steps toward the right, as a simpler function did, but all at once. The javascript console returned an error <br /><br />&quot;missing ; before statement<br />Source File: movetest.html<br />Line: 33, Column: 27<br />thebox.style.left=&quot;+x+&quot;px&quot;&quot;;&quot; <br /><br />with a green dotted line and an arrow pointing to the last word before the equal sign, indicating I forgot to define something or completely misunderstood how to change the code. Here is the entire function:<br /><br />function run()<br /> &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp;if(running) <br /> &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;clearTimeout(running);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;running &nbsp;= 0;<br /> &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;running = setTimeout(&quot;run()&quot;, speed);<br /><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (document.getElementById)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x=x+steps;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var thebox = document.getElementById(&quot;mask&quot<img src="/images/emoticons/wink.png" class="smiley" />;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thebox.style.left=&quot;&quot;+x+&quot;px 7px&quot;;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp;}<br /><br />Can this kind of action be accomplished from this function? Or should I completely rethink the code? Eventually I intend for an &quot;opaque&quot; div block to move right slowly, uncovering a graphic underneath in a sort of pseudo-scroll.]]></description>
    <pubDate>07/20/04, 202 48 2004 2004:%i:1090356527 16:48:47</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1109</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1110</link>
    <description><![CDATA[<blockquote> thebox.style.left=&quot;+x+&quot;px&quot;&quot;;&quot; </blockquote><br /><br />This is all wrong, wherever it came from.<br /><br />thebox.style.left=&quot;&quot;+x+&quot;px 7px&quot;;<br /><br />should work<br /><br />&quot;&quot; is a blank string but makes sure that the number x is treated as a string and not a number. If x is 12 then the string would become<br /><br />thebox.style.left=12px 7px;<br /><br />Have you delared the variables at the top of the script outside the functions? Look ate the actual source code of the examples.]]></description>
    <pubDate>07/20/04, 202 11 2004 2004:%i:1090361499 18:11:39</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1110</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1111</link>
    <description><![CDATA[I agree that it is wrong, but I'm thinking that a loop might be a better way to approach it.<br /><br />What I want is for a div block to start in one specific position horizontally, then move in gradual steps to the right until it reaches another specific position horizontally. The vertical position should be unchanged.<br /><br />My basic problem is not being clear how the timer can moderate &nbsp;the steps so the box moves deliberately rather than all in a rush. I looked at source from two examples on the WPDFD site:<br /><br />http://www.wpdfd.com/editorial/ticker.htm<br /><br />the newsticker example and:<br /><br />http://www.wpdfd.com/editorial/prax.html<br /><br />the horserace example. Both have timers, and the horserace example seems to be the closest to the effect I need, but the complex use of arrays in it leaves me uncertain what the 'core' code is. Also, the horserace adds a random math operator to make the results variable, something which I don't need. The ticker appeared to be simpler, but obviously I'm breaking something by either leaving it out or not declaring a variable correctly. <br /><br />I'm going to try and rebuild it again as simply as I can. A possible problem is that some elements of the code I posted were additional functions [stop(), kickstart(), etc.], which I really didn't need. I'll begin by defining a beginning point, an end point, and then attempt to use a timer to scroll the div block smoothly from one to the other on the horizontal axis, then stop at the end point. I believe all that can be put into one function, but since javascript is not easy for me, I'll have to do a lot of reading of references.<br /><br />The reason I'm so optimistic that it can be done is that your other examples of javascript and CSS working together:<br /><br />http://www.wpdfd.com/editorial/wpd0404footnote.htm<br /><br />the 'film strip' rollover footnote and:<br /><br />http://www.wpdfd.com/editorial/wpd0103.htm<br /><br />the 'scripting the box' editorial deconstructed very easily and allowed me to do a flash-like menu that displayed a different picture each time in the same place. The timer is what's giving me fits though, and if you know of any other examples that show a timer affecting an element as I have described, I'd love to look at them. ]]></description>
    <pubDate>07/20/04, 202 09 2004 2004:%i:1090368597 20:09:57</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1111</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1112</link>
    <description><![CDATA[Okay, i've put a little demo up at<br /><br />http://www.wpdfd.com/editorial/movebox.html<br /><br />and commented the script.<br /><br />Timers are a bit confusing, they don't work as you would expect.<br /><br />What is happening here is there is a function moveBox() which shifts the position of the box. Sorry, I didn't spot the error in the previous post but thebox.style.left should, of course, only have one value, not two like backgroundPosition. It can either be a number...<br /><br />thebox.style.left=200;<br /><br />or a string<br /><br />thebox.style.left=&quot;&quot;+x+&quot;px&quot;;<br /><br />Get into the habit of breaking down scripts into smaller functions that do less and less to discover what does what.<br /><br />The 'move' link will just call the moveBox() function once, so you only get a single step.<br /><br />The run() function is a loop which runs from 0 to 100. For each step, a timeout event is created for the timer 'time1'. The loop is programming the timer to do something 100 times with a delay of 10 (speed) milliseconds between each event. The timer is disposed of when it has fulfilled its purpose. clearTimeout(time1).<br /><br />Programming the timer is almost instantaneous and it all happens before the box actually moves. That is the hard part to grasp!<br /><br />Hopefully, this simple little 'building block' will get you on your way.]]></description>
    <pubDate>07/21/04, 203 51 2004 2004:%i:1090403509 05:51:49</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1112</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1113</link>
    <description><![CDATA[Yes, that's exactly the behavior I was looking for! With this example, I should be able to create the code to fit my needs. Thanks for clarifying how the timer works. Your code is far more elegant than what I had dimly blocked out in my mind. I had already created a movebox function, so the only thing I was missing was the index and timer. Adding the extra link to show how the movebox worked on its own was helpful.<br /><br />Thanks for taking the time to clear the fog from my mind.]]></description>
    <pubDate>07/21/04, 203 24 2004 2004:%i:1090423455 11:24:15</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1113</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1114</link>
    <description><![CDATA[I'm having a bit of trouble altering the code you gave me. Here is an example of what I'm doing<br /><br />http://jwmpc.com/nemredes/girlsof04%20copy.html<br /><br />what I wanted to do was pass a variable through the run function to movebox function to move three separate boxes independently. <br /><br />I tried just adding a variable to the run function, but when I tried to use that variable in the movebox function nothing happened.<br /><br />Should I create three timers, and assign a separate box name for each? That produced another problem, which was the box would move to the last x position, regardless of the starting value of the variable. Does this mean I should define three global variables (x,y,z)?<br /><br />I'll try that approach, but if you have another idea, I'd appreciate it.]]></description>
    <pubDate>07/29/04, 211 22 2004 2004:%i:1091103756 08:22:36</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1114</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1115</link>
    <description><![CDATA[As you have three objects, they need to be treated separately. The best way to do that is with arrays...<br /><br />So, you have thebox[1], thebox[2] and thebox[3]. Also bx[1],bx[2] and bx[3] - time[1], time[2] and time[3]<br /><br />The you can just specify which box to move by passing a parameter run(1), run(2) or run(3)<br /><br />Are you with me there? You can see how arrays work in my horse race code - http://www.wpdfd.com/editorial/prax.html<br /><br />Otherwise, you need three of everything with different names!]]></description>
    <pubDate>07/29/04, 211 31 2004 2004:%i:1091115090 11:31:30</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1115</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1116</link>
    <description><![CDATA[Yes, I was thinking that would be a good example to use, since it had multiple arrays. Didn't think about creating three &quot;time&quot; objects though, and I am unclear as to how to reset the boxes to their original position. The horserace simply says to reload the page. I'll be wrestling with this code for a while, then let you know what I discovered.]]></description>
    <pubDate>07/29/04, 211 11 2004 2004:%i:1091131876 16:11:16</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1116</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1117</link>
    <description><![CDATA[Are the square brackets you use in your reply above an indication that I should declare all of these items as global variables, or are square brackets and parentheses interchangable?]]></description>
    <pubDate>07/29/04, 211 32 2004 2004:%i:1091136728 17:32:08</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1117</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1118</link>
    <description><![CDATA[Square brackets are used for array dimension. They are not interchangeable.<br /><br />Before you can use an array, you should declare it at the top of your JavaScript...<br /><br />var v = new Array();<br />v[1]= -50;<br />v[2]= -50;<br />v[3]= -50;]]></description>
    <pubDate>07/30/04, 212 15 2004 2004:%i:1091164525 01:15:25</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1118</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1119</link>
    <description><![CDATA[So...<br /><br />I need to make three arrays:<br /><br />bx[1,2,3]<br />time[1,2,3]<br />theBox[1,2,3]<br /><br />at the beginning of the javascript, outside of the function, then call the arrays...<br /><br />bx[n].style.left=x;<br />time[n]=setTimeout('moveBox(n)',speed*i);<br />var bx[n]=document.getElementById(&quot;theBox[n]&quot<img src="/images/emoticons/wink.png" class="smiley" />;<br /><br />and I don't have to declare local variables with var? Should I do the same with the clearTimeout, ie clearTimeout(time[n])<br /><br />Just thinking in text here, I'll try this on my own.<br />]]></description>
    <pubDate>07/30/04, 212 25 2004 2004:%i:1091215505 15:25:05</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1119</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1120</link>
    <description><![CDATA[Mmm, not sure about this from the way you've written it but you do need to clear the timeouts as you suggested.<br /><br />Thump the floor if you want to give up <img src="/images/emoticons/wink.png" class="smiley" />]]></description>
    <pubDate>07/30/04, 212 46 2004 2004:%i:1091216776 15:46:16</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1120</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1121</link>
    <description><![CDATA[Actually, after reading a few quick references on the web about arrays, and how they are used, I can dimly grasp what's needed. What I'm not sure about is if I have to define each element of the array. I'll show you what I have(which does precisely nothing):<br /><br />var bx = new Array(3);<br />var theBox = new Array(3);<br />var time = new Array(3);<br /><br />function run(n)<br /> &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp;index=108; // the initial left position<br /> &nbsp; &nbsp; &nbsp;for (i=0;i&lt;=369;i++) // set a loop of 369 steps<br />  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;time[n]=setTimeout('moveBox(n)',speed*i); <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;clearTimeout(time[n]); <br /> &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp;<br />function moveBox(n)<br /> &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp;if (document.getElementById)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var bx[n]=document.getElementById(&quot;theBox[n]&quot<img src="/images/emoticons/wink.png" class="smiley" />; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bx[n].style.left=x; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x++;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp;}<br /><br />Now I can see adding three definitions to the array like this:<br /><br />var bx = new Array(3)<br />bx[0] = ?;<br />bx[1] = ?;<br />bx[2] = ?;<br /><br />but what value would I assign to each element? The element theBox[]?<br /><br />I'm not ready to thump the floor yet, but I'm a bit frantic. ]]></description>
    <pubDate>07/30/04, 212 01 2004 2004:%i:1091217691 16:01:31</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1121</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1122</link>
    <description><![CDATA[I cheated, sorry. Just created three different functions, and three global variables, then altered them for each box. It's inelegant, but it works. The array solution is just beyond my fingertips.]]></description>
    <pubDate>07/30/04, 212 46 2004 2004:%i:1091220364 16:46:04</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1122</guid>
   </item>
     <item>
    <title>Jwmpc  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1123</link>
    <description><![CDATA[As an aside, the doctype declaration my code editor uses (Pagespinner) has a bit in it that completely breaks the moveBox functions. It is:<br /><br />http://www.w3.org/TR/html4/loose.dtd<br /><br />I discovered this when I tried to emulate your first example and it wouldn't work. After painstaking examination, the only difference I could see between your code and mine was the doctype declaration, and when I removed the offending bit, functionality returned.<br /><br />I'm not sure why Pagespinner includes this, or why that dtd prevents using the moveBox() function, but that's one reason why I'm as harried as I sound right now. Hope it wasn't vital.]]></description>
    <pubDate>07/30/04, 212 05 2004 2004:%i:1091221544 17:05:44</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/scripting/confused_about_moving_a_div_block/#p1123</guid>
   </item>
   </channel>
</rss