473,545 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text Effects

iam_clint
1,208 Recognized Expert Top Contributor
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 7717
kovik
1,044 Recognized Expert Top Contributor
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 Recognized Expert Moderator MVP
To avoid invalid markup, you could use the class attribute instead.
Jul 3 '07 #3
gits
5,390 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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
72023
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 can type straight away Thanks in advance
47
7570
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 a better solution. lq 'start code:
23
2345
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
3211
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 2+2, the value 4 *is produced*. Nothing *happens*. Thus, 4 is the value of the expression, and it has no side effects. In the expression g=2.0, the...
20
2826
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 become obnoxious, especially on commercial sites. To a large extent, dhtml text effects have been replaced by flash, likely because the flash...
0
1215
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 database online the same text formatting effects doesnt apply.... when i select the font color as red and click the button , the same effects doesnt takes...
6
4907
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++ world? Is it like something that is not desired but happens automatically and we cannot prevent it? Would be great if someone throws light on...
12
2525
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 effects. Just wanted to know how to do such a thing. Just point me to the direction that I should get to do such a effect. any tutorial, Link. ...
4
3020
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
7415
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7440
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5997
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.