Current location: Hot Scripts Forums » General Web Coding » JavaScript » angle rotation


angle rotation

Reply
  #1 (permalink)  
Old 11-11-09, 05:48 AM
hemi hemi is offline
Wannabe Coder
 
Join Date: Aug 2009
Posts: 117
Thanks: 15
Thanked 0 Times in 0 Posts
angle rotation

<html>
<head>
<STYLE>
.positioned { position: relative; }
</STYLE>
<SCRIPT>
var id = 0;
function displayTextDiagonal (text, down, deg, lsp)
{
deg = deg || 90 ;
deg = Math.PI / 180 * deg;
lsp = lsp || 10;
dy = lsp * Math.tan(deg);
var html = '';
html += '<DIV ID="td' + id + '"' + ' CLASS="positioned"' + '>';
if (down)
{
for (var r = 0; r < text.length; r++)
{
html += '<SPAN ID="td' + id + r
+ '" CLASS="positioned" STYLE="left: '
+ (r * lsp) + 'px; top: ' + (r * dy) + 'px;">';
html += text.charAt(r);
html += '</SPAN>';
}
}
else
{
for (var r = 0; r < text.length; r++)
{
html += '<SPAN ID="td' + id + r
+ '" CLASS="positioned" STYLE="left: '
+ (r * lsp) + 'px; top: '
+ ((text.length - r) * dy) + 'px;">';
html += text.charAt(r);
html += '</SPAN>';
}
}
html += '<\/DIV>';
id++;
document.write(html);
}
</SCRIPT>
<body>
<center><br><br><br>
<script>

displayTextDiagonal('chandra', true, 90, 2);
displayTextDiagonal('sekhar',false,80,6);
</SCRIPT>
</center>
<SCRIPT>


</body>
</html>



i got this code from google can any one tell me

1)deg= deg || 90;


wht this line is doing there in the function


2) in the body tag a function is going from script can i do same thing by div
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-11-09, 06:03 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
deg = deg || 90;
If deg is defined, not false, not null, and not 0, deg is set to its current value. Otherwise it's set to 90.

The OR operator (||) works by evaluating its left side and then returning the left or right side depending on if the evaluation was true/false.

If you wrote
Code:
var a = false || 5;
a would be 5 because the expression 'false' is of course false.

If we instead did
Code:
var a = 5;
var b = 1+a || 56;
b would be 6 because 1+a==6 and any number but 0 evaluates to true in an expression.

The AND (&&) operator can be used the same way. It returns its left side if it evaluates to true, in any other case it returns its right side.

I'm not sure what you mean by your other question.

You are missing a </head> between </SCRIPT> and <body> and you have an extra <SCRIPT> at the end.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [2005 ] DrawString on an angle? tim8w Windows .NET Programming 1 01-22-09 07:05 PM
Exif rotation Wordcall PHP 1 01-20-07 03:40 PM
looking for PHP script for timed image rotation + link rotation rob1005 Script Requests 0 12-09-06 02:03 AM
Immediate Javascript Help Needed - Image Rotation 170Designs JavaScript 1 07-14-06 12:10 AM
Is it possible to rebuild image rotation javascript to perform similar, but at the sa RomanRusso JavaScript 1 05-05-06 02:36 PM


All times are GMT -5. The time now is 12:23 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.