473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

Text Effects

iam_clint
1,208 Expert 1GB
Heres some sample code I wrote up for you guys to use on making text effects

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. //TEXT EFFECTS CODE WRITTEN BY iam_clint!
  3. window.onload = doEffects;
  4. var speed = 15; //lower the number the faster
  5. var color_speed = 50; //speed at which colors change
  6. var smoothing = 8; //the larger the number the less smooth but faster for sliding.
  7. var font_smoothing = 1; //lower the number the smoother the font changes.
  8. var start_top = 0;
  9. var start_left = 0;
  10. //setting global variables
  11. var curele = "";
  12. var slidedown = "";
  13. var start_topSD = "";
  14. var slideup = "";
  15. var start_topSU = "";
  16. var slideright = "";
  17. var start_leftSR = "";
  18. var slideleft = "";
  19. var start_leftSL = "";
  20. var zoomin = "";
  21. var zoomout = "";
  22. var start_zoomSize = "";
  23. var start_zoomSize0 = "";
  24. var colors = "";
  25. var R = "00";
  26. var G = "00";
  27. var B = "00";
  28. function doEffects() {
  29. var elements = document.getElementsByTagName("DIV");
  30. for (i=0; i<elements.length; i++) {
  31. var c = elements[i].getAttribute("effect").split(",");
  32. for (b=0; b<c.length; b++) {
  33. //elements[i].getAttribute("effect")
  34.     if (c[b] == "slidedown") { preset(elements[i]); start_topSD = elements[i].style.top; elements[i].style.top = 0; slidedown = window.setInterval("eSlideDown('"+curele+"')", speed); }
  35.     if (c[b] == "slideup") { preset(elements[i]); start_topSU = elements[i].style.top; elements[i].style.top = document.documentElement.offsetHeight; slideup = window.setInterval("eSlideUp('"+curele+"')", speed); }
  36.     if (c[b] == "slideright") { preset(elements[i]); start_leftSR = elements[i].style.left; elements[i].style.left = 0; slideright = window.setInterval("eSlideRight('"+curele+"')", speed); }
  37.     if (c[b] == "slideleft") { preset(elements[i]); start_leftSL = elements[i].style.left;  start_topSD = elements[i].style.top; elements[i].style.left = document.documentElement.offsetWidth; slideleft = window.setInterval("eSlideLeft('"+curele+"')", speed); }
  38.     if (c[b] == "zoomin") { preset(elements[i]); start_zoomSize = elements[i].style.fontSize; elements[i].style.fontSize = "0px"; zoomin = window.setInterval("eZoomIn('"+curele+"')", speed); }
  39.     if (c[b] == "zoomout") { preset(elements[i]); start_zoomSizeO = elements[i].style.fontSize; elements[i].style.fontSize = "100px"; zoomout = window.setInterval("eZoomOut('"+curele+"')", speed); }
  40.     if (c[b] == "colors") { preset(elements[i]); colors = window.setInterval("eColors('"+curele+"')", color_speed); }
  41. }
  42. }
  43. }
  44.  
  45. function preset(ele) {
  46.  curele = ele.getAttribute("id");
  47. }
  48. function calcHex(val) { hex = val; if (val==10) { hex = "A"; } if (val==11) { hex = "B"; } if (val==12) { hex = "C"; } if (val==13) { hex = "D"; } if (val==14) { hex = "E"; } if (val==15) { hex = "F"; } return hex; }
  49. function eSlideDown(eleid) { var ele = document.getElementById(eleid); if (parseFloat(ele.style.top)<parseFloat(start_topSD)) { ele.style.top = Math.floor(parseFloat(ele.style.top)+smoothing)+"px"; } else { ele.style.top = start_topSD; window.clearInterval(slidedown); } }
  50. function eSlideUp(eleid) { var ele = document.getElementById(eleid); if (parseFloat(ele.style.top)>parseFloat(start_topSU)) { ele.style.top = Math.floor(parseFloat(ele.style.top)-smoothing)+"px"; } else { ele.style.top = start_topSU; window.clearInterval(slideup); } }
  51. function eSlideLeft(eleid) { var ele = document.getElementById(eleid); if (parseFloat(ele.style.left)>parseFloat(start_leftSL)) { ele.style.left = Math.floor(parseFloat(ele.style.left)-smoothing)+"px"; } else { ele.style.left = start_leftSL; window.clearInterval(slideleft); } }
  52. function eSlideRight(eleid) { var ele = document.getElementById(eleid); if (parseFloat(ele.style.left)<parseFloat(start_leftSR)) { ele.style.left = Math.floor(parseFloat(ele.style.left)+smoothing)+"px"; } else { ele.style.left = start_leftSR; window.clearInterval(slideright); } }
  53. function eZoomIn(eleid) { var ele = document.getElementById(eleid); if (parseFloat(ele.style.fontSize)<parseFloat(start_zoomSize)) { ele.style.fontSize = Math.floor(parseFloat(ele.style.fontSize)+font_smoothing)+"px"; } else { ele.style.fontSize = start_zoomSize; window.clearInterval(zoomin); } }
  54. function eZoomOut(eleid) { var ele = document.getElementById(eleid); if (parseFloat(ele.style.fontSize)>parseFloat(start_zoomSizeO)) { ele.style.fontSize = Math.floor(parseFloat(ele.style.fontSize)-font_smoothing)+"px"; } else { ele.style.fontSize = start_zoomSizeO; window.clearInterval(zoomout); } }
  55. function eColors(eleid) { var ele = document.getElementById(eleid); R = calcHex(Math.floor(Math.random()*15))+''+calcHex(Math.floor(Math.random()*15)); G = calcHex(Math.floor(Math.random()*15))+''+calcHex(Math.floor(Math.random()*15)); B = calcHex(Math.floor(Math.random()*15))+''+calcHex(Math.floor(Math.random()*15)); ele.style.color = "#"+R+G+B; }
  56. </script>
  57. <!--<div name="txtEffect" effect="slideleft" id="id4" style="position: absolute; top: 50px; left: 500px;"><font color="red">This text should slide in from the right</font></div>
  58. <div name="txtEffect" effect="slideleft" id="id5" style="position: absolute; top: 150px; left: 500px;"><font color="blue">This text should slide in from the right</font></div>
  59. <div name="txtEffect" effect="slideleft" id="id6" style="position: absolute; top: 250px; left: 500px;"><font color="green">This text should slide in from the right</font></div>
  60. <div name="txtEffect" effect="slideleft" id="id7" style="position: absolute; top: 350px; left: 500px;"><font color="orange">This text should slide in from the right</font></div>
  61. <div name="txtEffect" effect="slideright" id="id8" style="position: absolute; top: 100px; left: 500px;"><font color="red">This text should slide in from the left</font></div>
  62. <div name="txtEffect" effect="slideright" id="id9" style="position: absolute; top: 200px; left: 500px;"><font color="blue">This text should slide in from the left</font></div>
  63. <div name="txtEffect" effect="slideright" id="id10" style="position: absolute; top: 300px; left: 500px;"><font color="green">This text should slide in from the left</font></div>
  64. <div name="txtEffect" effect="slideright" id="id11" style="position: absolute; top: 400px; left: 500px;"><font color="orange">This text should slide in from the left</font></div>-->
  65. <div name="txtEffect" effect="slidedown,colors" id="id1" style="position: absolute; top: 300px; left: 0px;">This text should slide down from the top and change colors</div>
  66. <div name="txtEffect" effect="slideright" id="id3" style="position: absolute; top: 300px; left: 360px;"><font color="red">This text should slide in from the left</div>
  67. <div name="txtEffect" effect="zoomout,slideleft" id="id4" style="position: absolute; top: 300px; left: 600px; font-size: 20px;"><font color="green">This text should slide in from the right and zoom out</div>
  68. <div name="txtEffect" effect="zoomin,slideup,colors" id="id5" style="position: absolute; top: 500px; left: 300px; font-size: 40px;">This text should Zoom in to size (zoom in) and slide up and change colors</div>
  69.  
Jun 1 '07 #1
4 7707
kovik
1,044 Expert 1GB
I like and don't like how it's given it's own attribute. I like the concept, but I don't like adding invalid markup. It does look like it works nicely though.

Since this is creating animation effects, I'd add a little extra optimization in the series of ifs by making them else ifs to avoid checking them all. Other than that, this script is solid. Very nice work. :D
Jul 1 '07 #2
acoder
16,027 Expert Mod 8TB
To avoid invalid markup, you could use the class attribute instead.
Jul 3 '07 #3
gits
5,390 Expert Mod 4TB
hmmm ... the old 'philosophical' question ;) : custom attribute vs. class ...

i think it is really a question that is up to the 'taste' of the developer with advantages and disadvantages on both sides ... using a custom attribute makes the html invalid but describes what you really want to do ... to add an attribute that holds a value you need ... it's the straight way and from my point of view it is semantically correct until everybody who reads that will know what you want to do ... but: it makes the markup invalid! using the class-attribute avoids that problem, but you misuse it and you loose the semantic ... an attr-name like 'effect' shows what you want to have there ... class is always class ... so: there are the two possibilities and, i know all xhtml-evangelists will hate me for that ;), i would always prefer the custom-attribute way ...

kind regards
Jul 3 '07 #4
kovik
1,044 Expert 1GB
I'm writing a class that handle effects, and I chose to go with classes, requiring that the classes corresponding to events have a special class in their class attribute. However, when you put it into perspective, a custom attribute does seem like a good idea. I'll need to start a debate somewhere regarding this and get some opinions.
Jul 3 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: spence | last post by:
Hi All How do I make it so that when a user clicks in a search text field, the default entry (in this case "Search") is removed automatically - they are then faced with a blank search box and...
47
by: Lauren Quantrell | last post by:
I have constructed the following code that simulates the common rollover effect when moving the mouse over a label (this example makes the label bold.) I'm wondering if anyone has come up with...
23
by: Mantorok Redgormor | last post by:
Can emulation of the logical OR be done in standard C to obfuscate its use? So I don't have to use if(a||b) but instead make that even more obfuscated without its use but testing the same condition
5
by: Niklaus | last post by:
This is one of the posts that i got. ------------------------------ A "side effect" of an operation is something that *happens*, not something that *is produced*. Examples: In the expression...
20
by: cwdjrxyz | last post by:
There have been fancy dhtml text effects since the early days of javascript. The rainbow text effect was one of the early ones. While some such effects may be fun on private pages, they can easily...
0
by: vijay mathews | last post by:
hi i am developing a chat application tool for a company i have a problem..... i have written codings for text formatting such as color, size etc in vb.net..... but when it is connected to a...
6
by: Senthil | last post by:
Hi, Whenever i read a C++ book or a newsgroup posting, i come across the terms like " before the side effects completes" , "destructor with side effects" etc. What is this side effect mean in C++...
12
ak1dnar
by: ak1dnar | last post by:
Hi, This is my first post to flash forum.Need a favour from you guys. Please Refer to the this link.http://tha.jp In the left hand side of the web site you may find the text links with some...
4
by: Academia | last post by:
I get the following watch message: tsSource.Text.ToUpper() This expression causes side effects and will not be evaluated string The Text is &Edit
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.