Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • InvisionFree and Zetaboards Support
  • [ZB] Resolution Code
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Add Reply
[ZB] Resolution Code
Topic Started: Dec 8 2009, 04:13 PM (86 Views)
theschoot Dec 8 2009, 04:13 PM Post #1
Member Avatar
Want to learn Javascript :)

Posts:
79
Group:
Member
Member
#2,214
Joined:
Feb 3, 2009
Coding language
HTML/CSS
i was trying to do something like a resolution code (which edit one width), if the resulution is >=1024, but i can't figure that out:

Code:
 
<script type="text/javascript">
if ((screen.width>=1024))
{$("#copyright").before("jiha");
};
else{ $("#copyright").before('xyz');
};

</script>


what i'm making wrong?
Posted Image
Offline Profile Quote Post Goto Top
 
Gorgor Dec 8 2009, 05:04 PM Post #2
Hello

Posts:
1,182
Group:
Coding Staff
Member
#2,728
Joined:
Apr 2, 2009
Coding language
PHP
Well all of the stuff you enter in the board template is before the copyright, so when it's executed there is no copyright there.

You need to use $(function(){
Code:
 
<script type="text/javascript">
$(function(){
if (screen.width>=1024) {
$("#copyright").before("jiha");
} else {
$("#copyright").before('xyz');
}
});
</script>
Edited by RedBldSandman, Dec 8 2009, 05:17 PM.
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
Offline Profile Quote Post Goto Top
 
RedBldSandman Dec 8 2009, 05:18 PM Post #3
Member Avatar
ZIPPY!

Posts:
479
Group:
Coding Staff
Member
#2,122
Joined:
Jan 25, 2009
Coding language
JavaScript
Also, you can't have semicolons after the if and else statements. I've edited Gorgor's example so just use that.
Posted Image
"To iterate is human, to recurse divine."

Offline Profile Quote Post Goto Top
 
Gorgor Dec 8 2009, 05:33 PM Post #4
Hello

Posts:
1,182
Group:
Coding Staff
Member
#2,728
Joined:
Apr 2, 2009
Coding language
PHP
Thanks. I didn't read the code, just saw that it needed the $(function(){ }) thing. :P
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
This forum is closed. Please visit http://zetascript.co.cc
Offline Profile Quote Post Goto Top
 
theschoot Dec 11 2009, 10:43 AM Post #5
Member Avatar
Want to learn Javascript :)

Posts:
79
Group:
Member
Member
#2,214
Joined:
Feb 3, 2009
Coding language
HTML/CSS
great thanks :D , but can i ask why i need to make a function there? :huh:
Posted Image
Offline Profile Quote Post Goto Top
 
Reid Dec 11 2009, 05:15 PM Post #6
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Coding language
JavaScript
theschoot
Dec 11 2009, 10:43 AM
great thanks :D , but can i ask why i need to make a function there? :huh:
Basically, a browser runs scripts as it comes across them. Since your script was either Above the Copyright or Below the Board that means that the code was ran before a copyright existed. Since when the code was ran there was no copyright, there wasn't an element to put the text node in front of - so it did nothing.

$(function() {}) is a shorthand for "when the DOM is ready." That means that the very second that all of the elements on the page are able to be accessed, it will run the code inside of it. $(function() {}) is roughly equivalent to the onload attribute on the body.

The problem with onload is that it will wait until all of the images on the page are done loading to execute code: that means that if you have big images on the page, the browser could have to wait until all of those are done loading to run your code. $(function() {}) bypasses this problem and runs the code when all of the elements are ready to be edited - not when all images, etc have loaded.

I do hope that makes sense..
Posted Image
Offline Profile Quote Post Goto Top
 
Vitality Dec 12 2009, 12:31 AM Post #7
Member Avatar
Tabula Rasa

Posts:
784
Group:
Former Staff
Member
#320
Joined:
Jul 26, 2008
Coding language
JavaScript
Cool, I did not know that.

And yes it makes sense Reid. Thank you for sharing :)
Offline Profile Quote Post Goto Top
 
theschoot Dec 12 2009, 11:24 AM Post #8
Member Avatar
Want to learn Javascript :)

Posts:
79
Group:
Member
Member
#2,214
Joined:
Feb 3, 2009
Coding language
HTML/CSS
wow thanks for that answer :) , easy to understand :D :D
Posted Image
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · InvisionFree and Zetaboards Support · Next Topic »
Add Reply

Track Topic · E-mail Topic Time: 5:20 PM Sep 3
Hosted for free by ZetaBoards