Jump to content

Nohana

Members
  • Content Count

    39
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Nohana

  • Rank
    Newbie
  1. Nohana

    Flexible Div

    Haha, I thought of that, but unfortunately it would involve some form of calculation where I know the value of window's height. I don't think that's feasible with CSS alone, not that I know of. Exactly what I was looking for. Thanks very much! =)
  2. Nohana

    Flexible Div

    I have two <divs> to work with in my page, red and green. red contains images and a title. Its size is fixed, 160px. green on the other hand is my content panel, where different information type will be placed. Because I don't know my user's actual window size, I would like to set green's height to automatically adjust itself so that it fits the entire window - 160px, which is the size of my title <div>. This way, not matter the size of my window, green height will always be (window.height-160px).How can I do that? :)For instance, should the user resize his window to 480px, then gr
  3. Thanks, it works now. :)One last question, is there no way to call the method directly from the function as in a static object, that it is, without having to ever create an object and store it in a variable? Similar to what you have with Math. Math.random is a method of Math, but it's not necessary to store Math in a variable at all.
  4. Hello,For a few hours now, I've been fiddling with my script to call a method, but the painful truth is that I don't know to create one, haha. I thought of doing things like one would do in Java but that doesn't seem to cut here in JS. Here's my code: function Player(){ function moveLeft() { alert("hidari!"); }} And: Player.moveLeft(); Technically, what this should do is pop up an alert box saying hidari. Needless to say, doesn't work. The way I'm handling the object (Player in this case) is obviously wrong, but I don't have a clue about how to to put things right. I googled for "javascri
  5. I managed to get things to work as intended regarding the inside function. function ClearGameTextEffect(){ //do something colors(); function colors() { //do something t2 = setTimeout( colors, 10 ); } } What I did was replace the parameter "colors()" (a string) in setTimeout with colors as shown above. But I'm still failing to grasp why it works one way but not another. Can anyone shed some light onto this? I'd feel safer after understanding the difference between directly passing function calls and passing them as a string. :)And my second question stands (lol). I did some googling and
  6. For me the only disadvantage would be I'd have to rename some variables... It's not obvious maybe, but I just replaced the actual content of my function with this counter thing, the actual function does something a little more complicated using some dozen of variables, thus why I'd prefer to keep the variables in the scope of a function rather than having global variables which I will only need for this particular code. :)I thought already of putting the function outside, though I'm wondering, is there no way to use a function from within a function? This is possible in Java, so I thought it'd
  7. Last problem I think... I have a certain function within another function and I need it to be run every 100 ms when ClearGameTextEffect() is called. function ClearGameTextEffect(){ var counter = 0; colors(); function colors() { document.getElementById("scoreText").innerHTML = counter; counter++; t2 = setTimeout( "colors()", 100 ); } } The code stops at t2 = setTimeout( "colors()", 100 );. I suppose you cannot or perhaps this is not the right way to call a function that is inside another function. Just how can I get this to work? :)Thanks again for all the help, guys. Really appreciate i
  8. 1. So there's no way to get this change to appear on my innerHTML, correct? I take the only way to do this would be for me pass the innerHTML as a string to some variable then edit it as a string and repass it back to the containing element. Anyways, I've managed to rid myself of the problem with the innerHTML and event handler. Though it's not perfect, it satisfies its purpose in my game. 2. Haha, yeah sometimes I do silly things. I didn't think of using 'null'. Would changing this make any impact on my code? I'm not sure if I want to go through the trouble taking out all the calls to VoidFun
  9. But that's resorting to an iteration. In addition to that, you're directly accessing many elements at a time which I want to avoid. And noting what I said in my 2nd post. The problem is with the function Dig(id). It does modify the event attributes of my elements, but only "behind the scenes", I can't see the change when I call my <div>'s innerHTML.Is there another way of accessing event attributes and modifying them other than document.getElementById("").event? Or even better, is there a way to access all attributes of an element with just one go? For example, when you can getElementByI
  10. Update:After analyzing the string txt, I have finally reached the ultimate problem in my code. It has nothing to do with the if true/false blocks as I previously thought, in fact it has to do with Javascript itself.To keep the problem brief and simple I will stick to the basics. I have the following element which appears several time within my <div> (for simplicity's sake, you can assume there's only one <img> inside <div>): <img id="1" class="button" src="button1.png" onmousedown="VoidFunction()" onmouseup="VoidFunction()" onmouseout="VoidFunction()" style="left: 0px; to
  11. I think you might be misunderstanding what I want to do. I'm not trying to change the event attributes for a single element, what I want is to replace specific sections that occur multiple times within a very large string. If you look at my code, the variable txt stores innerHTML of "map", that is, I'm not interested in "map" itself, I want its content only. I don't know if it helps but I'll post below a small portion of string txt to give a better idea of what I want: <img id="1" class="button" src="button1.png" onmousedown="VoidFunction()" onmouseup="VoidFunction()" onmouseout="VoidFunct
  12. Thanks. Haha. I figured it had something to do with the parentheses. :)Now I have a small second problem... function setButtonState( state ) { if ( state == "disable" ) { var txt; txt = document.getElementById("map").innerHTML; txt.replace(/onmousedown="PressButton\(id\)"/g, "onmousedown=\"VoidFunction()\"" ); txt.replace(/onmouseup="Dig\(id\)"/g, "onmouseup=\"VoidFunction()\"" ); txt.replace(/onmouseout="UnpressButton\(id\)"/g, "onmouseout=\"VoidFunction()\"" ); txt.replace(/cursor: pointer/g, "cursor: default" ); document.getElementById("map").innerHTML = txt; alert("OFF"); } else
  13. txt = txt.replace(/onmousedown=\"VoidFunction()\"/g, "onmousedown=\"PressButton(id)\""); This piece of code doesn't work... Can anyone help me out? :)Strangely, when I switch from /onmousedown=\"VoidFunction()\"/g to "onmousedown=\"VoidFunction()\"" the code works, but only for the first match it finds. I want it to do a global search and replace all instances of "onmousedown=\"VoidFunction()\"" . How can I do that? No iteration please, that's running away from the problem lol.(Additional note)I just tried txt = txt.replace(/src="button1.png"/g, "src=\"g_bullion.gif\""); And it works like
  14. Now this is a problem, the width/height of <div> are dependent on my text body. I'm looking for an independence case, where I can set any size I want to the <div> and don't have to worry about the size of the text inside the <div>.You can think of the <div> as small notes of fixed size (say, 200px, 200px). Sometimes I'll write a lot in them, sometimes I'll just write one word. My font-size can also vary from one note to another while my <div> (the note) remains the same size as always. In whichever case, my text will always be centerly aligned within the note. Als
  15. I figured I should've included some more detail. My container div must have position:absolute and some size (x,y). Other than that I can't think of any other relevant information.I've tried before to place the text inside another <div> and then try manipulating this <div> inside my main <div> instead of the text itself, but this proved somewhat complicated I failed to get result I intended.
×
×
  • Create New...