Dazzling projection (pure CSS + JS)

Source: Internet
Author: User
Tags passthrough
ArticleDirectory
    • Openlaszlo dhtml css 3 demo-to flash or not to flash, is no question!
Openlaszlo dhtml css 3 demo-to flash or not to flash, is no question!

By Raju bitter on August 25,200 9

Since the openlaszlo DHTML runtime has been released, I 've been wondering if there' ll ever be the time for me to say: "I can imagine that flash won't be a necessity for always Ally very appealing RIAs!" That time has come, thanks to the incredible work on great open source projects like the Firefox browser or WebKit.

Judge for yourself, here are two versions (DHTML/JavaScript and swf9) of a demo application, that was plain red by Zachary Johnson's great css3 text-shadow demo. this is the openlaszlo DHTML/JavaScript version of the demo, and as always with the advanced CSS features, you need a modern browser for it to work (I 've successfully tested with Firefox 3.5 +, Safari 4.x or WebKit nighly build, Google Chrome and opera 10 ):

Please upgrade your browser

And in case you wonder, what the swf9 version of this application looks like, here it is. even after so many years of working with openlaszlo it's still surprising to see how well the platform renders applications must SS runtimes.

I believe this demo underlines what I 've said in my previous blog, that openlaszlo can be one of the key keys ys to drive adoption of standards like HTML 5 and css3 extensions in the RIA space, providing a backup version of an application in flash for Internet Explorer 6/7 and older browsers. and who wocould choose flash, if you can get exact the same visual results with open standards!

Update: Some people have requested the source code for this example. this is the main LZX file, and here is a link to the ZIP file containing the graphic resources as well. I ran tested with openlaszlo 4.5.1 and trunk.

View plaincopy to clipboardprint?

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <! -- * Gpl_copyright_begin ************************************* **********
  3. * Copyright 2009 Raju bitter
  4. * Use is subject to license terms.
  5. * This program is free software: You can redistribute it and/or modify
  6. * It under the terms of the GNU General Public License as published
  7. * The Free Software Foundation, either version 3 of the license, or
  8. * Any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * But without any warranty; without even the implied warranty
  12. * Merchantability or fitness for a special purpose. See
  13. * GNU General Public License for more details.
  14. *
  15. * You shoshould have written ed a copy of the GNU General Public License
  16. * Along with this program. If not, see
  17. * Gpl_copyrightincluend ************************************** **************** -->
  18. <Canvas width = "600" Height = "400" bgcolor = "# ffffff" proxied = "true">
  19. <! -- Resources -->
  20. <Resource Name = "spotlightres" src = "spotlight.png"/>
  21. <Resource Name = "openlaszlores" src = "OpenLaszlo-Header.png"/>
  22. <! -- Reposition boxes depending on mouse X-pos -->
  23. <Handler name = "onmousemove" reference = "LZ. globalmouse"> <! [CDATA [
  24. VaR posx = canvas. getmouse ('x ');
  25. VaR posy = canvas. getmouse ('y ');
  26. If (posx> 0 & amp; posy> 0 & amp; posx <canvas. width & amp; posy <canvas. height ){
  27. Spotlight. setattribute ("X", (posX-spotlight.width/2 ));
  28. Spotlight. setattribute ("Y", (posY-spotlight.height/2 ));
  29. // Calculate Angel and distance
  30. VaR xx = posx-canvas. width/2;
  31. VaR YY = (posy-canvas. Height/2 );
  32. VaR distance = math. SQRT (math. Pow (XX, 2) + math. Pow (YY, 2 ));
  33. VaR angle = math. atan (yy/xx)/(math. PI/180 );
  34. If (XX <0 ){
  35. Angle + = 180
  36. }
  37. If (XX> = 0 & amp; YY <0 ){
  38. Angle + = 360
  39. }
  40. Thetext. setattribute ("distance", distance/2 );
  41. Thetext. setattribute ("angle", angle + 180 );
  42. }
  43. ]>
  44. </Handler>
  45. <Class name = "demotext" extends = "text">
  46. <! -- As3 import statements -->
  47. <Switch>
  48. <When property = "$ as3">
  49. <Passthrough>
  50. Import flash. Filters. dropshadowfilter;
  51. </Passthrough>
  52. </When>
  53. </Switch>
  54. <! -- Shadow distance -->
  55. <Attribute name = "distance" value = "12"/>
  56. <! -- Shadow angle -->
  57. <Attribute name = "angle" value = "0"/>
  58. <! -- Blur X -->
  59. <Attribute name = "blurx" value = "5"/>
  60. <! -- Blur y -->
  61. <Attribute name = "blury" value = "5"/>
  62. <! -- Xoffset for CSS Dropbox -->
  63. <Attribute name = "_ xoffset" value = "0"/>
  64. <! -- Yoffset for CSS Dropbox -->
  65. <Attribute name = "_ yoffset" value = "0"/>
  66. <! -- Reference to the Flash dropshadowfilter object -->
  67. <Attribute name = "shadowfilter" value = "null"/>
  68. <Handler name = "oninit">
  69. This. addboxshadow ()
  70. </Handler>
  71. <Method name = "addboxshadow">
  72. If ($ DHTML ){
  73. // LZ. Text clipping active, which wocould cut off the shadow in DHTML
  74. // Workaround for http://jira.openlaszlo.org/jira/browse/LPP-8415
  75. This. getmcref (). style. Overflow = "visible ";
  76. This. getmcref (). firstchild. style. Overflow = "visible ";
  77. This. getmcref (). firstchild. style. Clip = "";
  78. This.css calculateoffset ();
  79. VaR cssstring = "#333" + _ xoffset + "PX" + _ yoffset + "PX" + blurx + "PX ";
  80. Debug. Write (cssstring );
  81. This. getmcref (). style. textshadow = cssstring;
  82. } Else {
  83. /* Dropshadowfilter constructor values:
  84. * [Distance: Number]
  85. * [Angle: Number]
  86. * [Color: Number]
  87. * [ALPHA: Number]
  88. * [Blurx: Number]
  89. * [Blury: Number]
  90. * [Strength: Number]
  91. * [Quality: Number]
  92. * [Inner: Boolean]
  93. * [Knockout: Boolean]
  94. * [Hideobject: Boolean])
  95. */
  96. This. shadowfilter = new flash. Filters. dropshadowfilter (this. distance, this. angle,
  97. 0x333333, 0.95, this. blurx, this. blury, 1, 2, false );
  98. // Have to remove mask on Sprite for swf8 Runtime
  99. // Workaround for http://jira.openlaszlo.org/jira/browse/LPP-8426
  100. If ($ as2 ){
  101. This. Sprite. removemask ();
  102. }
  103. Updateswffilter ();
  104. }
  105. </Method>
  106. <Handler name = "onangle">
  107. If ($ as2 | $ as3 ){
  108. This. shadowfilter. angle = This. angle;
  109. This. shadowfilter. Distance = This. distance;
  110. This. shadowfilter. blurx = This. blurx;
  111. This. shadowfilter. blury = This. blurx;
  112. Updateswffilter ();
  113. } Else if ($ DHTML ){
  114. This.css calculateoffset ();
  115. VaR cssstring = "#333" + _ xoffset + "PX" + _ yoffset + "PX" + blurx + "PX ";
  116. This. getmcref (). style. textshadow = cssstring;
  117. }
  118. </Handler>
  119. <Method name = "updateswffilter">
  120. This. Sprite. getmcref (). Filters = [This. shadowfilter];
  121. </Method>
  122. <Method name = "csscalculateoffset">
  123. // Css3 doesn't use angle, but x/y offset. So we need
  124. // Translate from angle and distance to x and y offset for css3.
  125. // Math. Cos and math. Cos are based on radians, not degrees
  126. VaR radians = This. Angle * Math. PI/180;
  127. This. _ xoffset = math. Round (math. Cos (radians) * This. Distance );
  128. This. _ yoffset = math. Round (math. Sin (radians) * This. Distance );
  129. </Method>
  130. </Class>
  131. <Demotext align = "center" Y = "$ {canvas. Height/2-this.height}" id = "thetext" clip = "false"
  132. Fontsize = "70" fontstyle = "bold" fgcolor = "# 2c657a" opacity = "1.0"> openlaszlo </demotext>
  133. <View id = "wall" resource = "openlaszlores" Y = "$ {canvas. Height-180}"/>
  134. <View id = "spotlight" x = "$ once {canvas. width/2-this.width/2} "Y =" $ once {canvas. height/2-this.height/2} "resource =" spotlightres "/>
  135. </Canvas>
<? XML version = "1.0" encoding = "UTF-8"?> <! -- * Gpl_copyright_begin ************************************* * ********* Copyright 2009 Raju bitter * use is subject to license terms. * This program is free software: You can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the license, or * any later version. ** this program is distributed I N the hope that it will be useful, * but without any warranty; without even the implied warranty of * merchantability or fitness for a participant purpose. see the * GNU General Public License for more details. ** you shoshould have written ed a copy of the GNU General Public License * along with this program. if not, see 

and if you built some other cool demos with css3 or HTML5 support, please ping me!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.