Jump to content

MikeatW3S

Members
  • Posts

    50
  • Joined

  • Last visited

Everything posted by MikeatW3S

  1. Does this mean that you must have all the variable declared above the statements that will use them so that when the code is first seen the variables will be meaningful? Or must all the script be downloaded first from <script> to </script> before code is run?
  2. Oh cool! Exactly what I'm looking for. Question: Can I keep the background images on the server until needed? Or do I have to download all images before displaying them? Thanks.
  3. I don't know. Wouldn't it be a contradiction to have a button (or js) on a page that when pressed makes it a child frame in some other parent (that plays the background music), and then when pressed again closes its own parent but leaves itself intact? Can a child control its parent? I thought only a parent could control a child.
  4. I guess I'm looking for the basic instruction to change the background image. And then from there I can worry about whether to change it at various times or at various scroll locations. But I need the basic instruction first. Thanks.
  5. I'd like to change the background image to different images as the user scrolls through the page in order to provide some entertainment value to my site. How does one do that? Thanks.
  6. I'd like the user to enable some secondary background music while another audio file reads text for each page. There is a different audio file for each page that reads the page, and these audio files take precedence over any secondary background music. Yet I'd like the secondary background music to survive a page transition to give the impression of continued train of thought. Any ideas on how to do this? Many thanks.
  7. <thanks>, More Human Than Human, That really helps. If you don't mind, I have a few more questions that are probably easy for you. 1) Is it common practice to include on every page all the javascript (js) code that's common to every page? Or should I put this common code in a separate file and "link" to it on every page where it is used. If I link to it, what statement do I put on each page that will fetch the common js code? Do I put the common js file in the root directory or in a separate js directory? 2) All my code is for the purpose of synchronizing audio and scrolling, and cookies are used to pass user preferences (to play or not) from one page to the next. What should I do if a user's browser does not support HTML5 or if their cookies are disabled? Can I put some code on each page that downloads the common js code only if the browser supports HTML5 and cookies are enabled? What statements would do that? </thanks>
  8. Hi guys, I seem to have accomplished what I was looking for. I have questions about cleaning up the code. What goes where, when or if to link a js file instead of all the code on every page,. My questions are: 1) If I put different sections of javascript code between different <script>...</script> tags, will the various code sections access each others functions and variable? Or must each section be selfcontained? I'd like to put some of the page dependent code in one section and link to a js file with page independent code for the rest. Is that doable? 2) When does code in various places run? If I have code where global variables are declared (what's that called - global area?) does that run as soon as the browser gets that portion of code from the server? Or does it start to run only after all the code is loaded or after all the page is loaded? I already know about when onload = "myFunction()" runs and when onunload="myOtherFunction()" runs. I don't know when global code runs. 3) Where should code usually go, in the <head> section or in the <body> section? 4) What happens with timers when you leave a page? Do they continue to run, or are they automatically shut down? 5) What is common programming practice, to declare global variables that are used amongst the various functions, or to pass local variables to functions that have variables in there definition? Thanks again for your help.
  9. It seems different browsers scroll at different speeds than others. I suppose I could measure at run time how fast things are scrolling. Or maybe it's possible to find out what browser I'm in. How would I get that information? Thanks. PS. Or it may be that I had too many tabs open and this affected how the timer routine was serviced. I found that the scroll seems smoother if I set the time interval to 1ms and then count 20 of them before scrolling by one pixel. That way it seems that any problems get averaged out. PSS. Now I'm concerned that scrolling itself will interfere with calculations of paragraph positions. If I calculate at run time the position of the next paragraph (in order to position it at the correct time), then the window may scroll by a few pixels between getting the position of the scroll bar and getting the position of the paragraph with respect to the viewable window. This may throw off the calculation by a number of pixels. Perhaps the first thing I need to do after I load a page and before scrolling is to make a table at run time of how many paragraphs there are and their positions. Can I create an array that stops adding member when there are no more? How does that work?
  10. OK, I can scroll to various paragraphs and get a data-time corresponding to the its time in the audio. Now I'm ready to start writing code to actually scroll the screen slowly. And I have a couple of questions. All the automatic scrolling routines that I've seen rely on the setTimer() function. So I wonder if I set the timer to service a function too fast will this cause too much processing so that the fan turns on? Is there an optimum timer interval between scroll adjustments? Also, if I want to scroll very slowly, can I scroll by fractional steps such as by 0.1? Or must I scrollBy() using whole numbers? As always, any help is appreciated.
  11. Thanks. I'll give this a try and let you know. Why should the following work: while(element.nextElementSibling) { Does element.nextElementSibling evaluate to "true" or a number? Does the while(condition) work as long as condition is defined? Or was that not your point in your post? Thanks. PS. element = element.nextElementSibling does not seem to work. PSS. But this does work. I tried it: var indexp = 0; function GetYPosition() { var pelmnt = document.getElementById(indexp); indexp = indexp + 1; ... } It works with paragraph tags labeled as: <p id = 0 > Some text </p> <p id = 1 > Some more text </p> <p id = 3 > And even more text </p> Each time I call the function it processes the next paragraph.
  12. I'm thinking of using: var x = document.getElementById("item1").nextElementSibling to advance which paragraph to display. The trouble is that you have to call the next element by a function of what the present element is, which assumes you know that. I suppose I could relabel the item by which you call the next. I know how to call by id, but how do you get the id label from nextElementSibling? Any help is appreciated.
  13. Yea, that sounds like the way to go. Can I do something like <p id=2 data-time=00:40></p>? I'm concerned about mismatching data types between strings and numbers, again. And I heard that I don't necessarily need to use quotes on my attributes. I'm also thinking of something like <p id=2 data-time=00:40 onclick="setAudioTiming(00:40)"></p> and when someone clicks on that paragraph, I go to a function that sets the currentTime() of the audio to data-time. Will the onclick attribute work in <p>? Of course, if someone grabs the vertical scroll bar, I'll have to do some more serious calculations to adjust the audio time. But that doesn't sound like too much trouble. Thanks again for the help.
  14. So I will need to know the vertical position of certain paragraphs in the document and the time in the audio file where they are read. But I'd like to avoid keeping a table or array of vertical positions of all of the paragraphs with corresponding audio times, since any change of text size and/or window resizing will require a recalculation of the entire table of paragraph locations. I now know how to calculate the vertical position of a <p id="paragraph 1"> by id (or I can make that a <div id="paragraph 1"></div> if needed). So if I know the vertical position of the present paragraph that's being read, can I dynamically go out on the fly and find the next <p id="paragraph 2"> that will be farther down the document? Then I don't have to keep an array of paragraph locations. And I don't even have to know how many there are. I just process until there are no more paragraphs. Also, can I make a <p id="label">, where label is some number, say 1429? Then I can make the label the time marker itself. And when I find the next <p> tag, I will automatically have the time in the audio file where it starts to be read out. This also eliminates the need for a table of document locations and audio locations for each paragraph. Thank you for all your help in this project. P.S. Perhaps I can .getElementById("p1") and label each paragraph with id="p1", id="p2", id="p3", ... Then I might give each paragraph with the additional name="time", where "time" is the numeric value of the time where that paragraph is read. Is this doable? Thanks.
  15. Thank you, Foxy Mod. You've been a great help in this project. One problem I will have is that I cannot anticipate the size of the text and the size of the window in which it resides. The user may change all that. What I'd like to be able to do is to identify before any scrolling starts what the vertical coordinate of the starting text would be and what the vertical coordinate of the ending text would be. I know I can identify paragraphs with an id tag, and I could put paragraphs at the start and end with id tags with no text just for the purpose of getting there position. Is there a property or method that can report what the vertical position of elements WOULD BE (identified by id tags) without actually scrolling to them in the process? Also, can I make an onclick="myfunction()" attribute inside a <p> so that anytime anyone clicks on that paragraph, I can call a function that will set the currentTime() of the audio to the position that starts reading that text? That would be great. Thanks. P.S. For example, can I use the HTML DOM scrollHeight property? Maybe I can put the entire scrollable content inside a <div id="allStuff"> and get the entire size of the displayable content in pixels even if someone changes the text size or window size or both. Then maybe I can put the audibly read stuff in a <div id="readStuff"> and get the size of only the stuff read out loud. Together with window.innerHeght and window.pageYOffset I can manage to keep the text being read in the middle of the page.
  16. I have a website with text, and I have an audio file of a reading of that text (adding my own emphasis in the author's voice). What I'd like to do is synchronize the vertical scrolling of the text with the audio file so that the text that is being read out loud also appears in the middle of the window. And if anyone should drag the vertical scroll-bar to some text, then the audio timing will adjust to that portion of the text be read out loud. I'm not really sure how to go about that - what ways of do that are there? I have seen techniques to simply scroll vertically at whatever speed I would desire. And I suppose I could just match the timing to coincide with the audio. Or I have seen where I can assign each paragraph with its own id="xxx". Perhaps I could periodically get the currentTime() of the audio and force the paragraph by id to the middle of the window (no matter what the size of the text or window). What DOM references and javascript statements would I have to look up to do that? Or if anyone should have a better idea, I would certainly like to hear about it. Thanks.
  17. Thanks for the help. You've been very generous. I got the play and volume settings to survive page transistions using cookies.
  18. Yea, it should have been, for (var i=0; instead of for (var 1=0; ... Which brings up a question. I'm using Microsoft Expression Web 4. Is there a better programming environment software that will catch errors? For example, is Dreamweaver better at catching javascript errors? Thanks.
  19. Here is the code I'm working with. I think there is something wrong with the getCookieValue() function. If I comment out (/*) the definition of the getCookieValue() function and comment out (//) the assignment statement that calls it in the cookieValue() function, then I can at least get the alert statement to display. If I deliberates put a typo in the setCookie() function then I don't get to the alert statement. And when I correct the typo in setCookie(), then I do get to the alert message. This is how I know that the getCookieValue() function must be the culprit. Is there something wrong with the return"" statement in getCookieValue()? Or do I need to be more careful with spaces when searching through the cookie string? Or could it be the fact that I am working on a localhost server. Does that prevent cookies from operating correctly. I'm sorry to make you look through the code. But I'm hoping this is easy for you. Thanks again. <!DOCTYPE html><html><body> <button onclick = "cookieValues()" type="button">Set and get cookie value:</button> <script> function cookieValues() { var IsPlayOnValue = 13; setCookie("IsPlayOn", 5, 33); IsPlayOnValue = getCookieValue("IsPlayOn"); alert("IsPlayOn is set to: " + IsPlayOnValue); } function setCookie(cookieName, cookieValue, expdays) { var expdate = new Date(); expdate.setDate(expdate.getDate() + expdays) ; document.cookie = cookieName + "=" + cookieValue + "; expires=" + expdate.toUTCString() + "; path=/"; } function getCookieValue(cookieName) { var thisCookie = document.cookie.split("; "); for (var 1=0;i<thisCookie.length;i++) { if (cookieName == thisCookie.split("=")[0]) { return thisCookie.split("=")[1]; } } return ""; } </script> </body></html>
  20. Yes, that is the tutorial I am refering to. I understand from it that if your function returns a value, you can use a variable assignment to a function to call that function. But I see a potential problem of calling a function by assigning it to a variable if the function returns nothing at all, like the setCookie() function. Won't that give you an error to assign a variable to nothing? I've seen elsewhere where I can simply have a line of code that state: setCookie(A,B,C); It works, but then I'm told that makes it a global function, which I think means it can be called by any webpage in any tab in the browser. Is there a work-around so that the function can only be called by the webpage in which you want to use it? Thanks. P.S. I did find this: http://www.w3schools.com/js/js_function_invocation.asp It talks more about what object owns the function. Correct me if I'm wrong, but I think my best approach would be something like this: var myCookieSetObject = { setCookie: function (cookieName, cookieValue, expdays) { var expdate = new Date(); expdate.setDate(expdate.getDate() + expdays) ; document.cookie = cookieName + "=" + cookieValue + "; expire=" + expdate.toGMTString() + "; path=/"; } } and then call it using: myCookieSetObject.setCookie(cookieName, cookieValue, expdays); Then the owner of the function is myCookieSetObject on the current page so there is no conflict with that function being run on different tabs in the web browser. Does this all seem right? Thanks again.
  21. Thank you, Foxy Mod. You've been a fine help. One more easy question (for you). How to call functions... Do I have to set a variable equal to a function as shown in the tutorial here? Or can I simply have a line of code that states, for example: setCookie(CookieName, CookieValue, expdays); It's not clear from the tutorial here if this is a legal function call procedure. Thanks.
  22. Is this a valid cookie setting function? (I found it on the internet and modified it a bit) function setCookie(cookieName, cookieValue, expdays) { var expdate = new Date(); expdate.setDate(expdate.getDate() + expdays) ; document.cookie = cookieName + "=" + cookieValue + "; expire=" + expdate.toGMTString() + "; path=/"; } Do I have the order of exprie and path correct? Do I need to take out any spaces? And if I call the function with the same cookieName but different cookieValue, this will simply overwrite the previous cookieName with a different cookieValue and expiration date, right? Thanks.
  23. So how do you change a cookiename's value? Do you simply write over it? What if it is a string of a different length? Does document.cookie=cookieName + "=" + cookieValue simply replace the previous cookieValue string with a different string even if it has a different length? If there are multiple cookies, does document.cookie go out and find the cookie of interest and change it if it already exists? When you create a function to find the value of a cookie you have to parse every character in the string and then find its value. I'm wondering if you have to do something similar when changing the value of a cookie or if that's handled by the document.cookie function.
  24. Can cookies store numerical data? Or do they only store information as text strings inside quotes? If I want to store the level of volume that has been set by the user, will I have to do a number to string conversion to store that info in the cookie, and then do a string to number conversion to set the volume property of the audio controls? What would be the javascript statements to do that conversion? As you can see I'm new to javascript. So I would appreciate any help. Thanks.
  25. My website has a number of webpages that each have an audio file that can be played for that page. When someone starts the audio, I want to save the volume and play settings so that the same settings will be used on the next page with the next audio file. If they start the audio on one page, I want to automatically start the audio for the next page with the same volume settings. Is there any ready code available to do this. I'm not really sure how to get started. Do I want to use cookies or session variables? Does that mean I need to go back and forth between php variables and javascript variables? Do both javascript and php use the same convention when accessing HTML DOM objects? Any help would be appreciated. Thanks.
×
×
  • Create New...