ITPub博客

首页 > IT职业 > IT图书 > CSS制作很漂亮的文字滑动效果

CSS制作很漂亮的文字滑动效果

IT图书 作者:chunzhisu 时间:2014-10-20 10:33:17 0 删除 编辑

点击(此处)折叠或打开

  1. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  2. <html xmlns=\"http://www.w3.org/1999/xhtml\">
  3. <head>
  4. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />
  5. <title>无标题文档-石家庄花卉</title>
  6. </head>
  7. <style type=\"text/css\">
  8. <!--
  9. body,div,ul,li,p,h1,h2{ margin:0; padding:0; border:0; background:#FAFAFA; font-family:Arial, Helvetica, sans-serif,\"宋体\"}
  10. body{ text-align:center; font-size:12px}
  11. li{ list-style:none}
  12. .rolinList{ width:402px; height:auto; margin:20px auto 0 auto; text-align:left}
  13. .rolinList li{margin-bottom:1px;border:1px solid #DADADA}
  14. .rolinList li h2{ width:380px; height:40px; background:#fff; font-size:14px; line-height:40px; padding-left:20px; color:#333; cursor:pointer}
  15. .content{ height:150px;width:400px; background:#fff; background:#FAFAFA}
  16. .content p{ margin:12px}
  17. -->
  18. </style>
  19. <script type=\"text/javascript\">
  20. //<![CDATA[
  21. window.onload = function() {
  22. rolinTab(\"rolin\")
  23. }
  24. function rolinTab(obj) {
  25. var list = $(obj).getElementsByTagName(\"LI\");
  26. var state = {show:false,hidden:false,showObj:false};
  27. for (var i=0; i<list.length; i++) {
  28. var tmp = new rolinItem(list[i],state);
  29. if (i == 0) tmp.pShow();
  30. }
  31. }
  32. function rolinItem(obj,state) {
  33. var speed = 0.0666;
  34. var range = 1;
  35. var interval;
  36. var tarH;
  37. var tar = this;
  38. var head = getFirstChild(obj);
  39. var content = getNextChild(head);
  40. var isOpen = false;
  41. this.pHidden = function() {
  42. if (isOpen) hidden();
  43. }
  44. this.pShow = show;
  45. var baseH = content.offsetHeight;
  46. content.style.display = \"none\";
  47. var isOpen = false;
  48. head.onmouseover = function() {
  49. this.style.background = \"#EFEFEF\";
  50. }
  51. head.onmouseout = mouseout;
  52. head.onclick = function() {
  53. this.style.background = \"#EFEFEF\";
  54. if (!state.show && !state.hidden) {
  55. if (!isOpen) {
  56. head.onmouseout = null;
  57. show();
  58. } else {
  59. hidden();
  60. }
  61. }
  62. }
  63. function mouseout() {
  64. this.style.background = \"#FFF\"
  65. }
  66. function show() {
  67. head.style.borderBottom = \"1px solid #DADADA\";
  68. state.show = true;
  69. if (state.openObj && state.openObj != tar ) {
  70. state.openObj.pHidden();
  71. }
  72. content.style.height = \"0px\";
  73. content.style.display = \"block\";
  74. content.style.overflow = \"hidden\";
  75. state.openObj = tar;
  76. tarH = baseH;
  77. interval = setInterval(move,10);
  78. }
  79. function showS() {
  80. isOpen = true;
  81. state.show = false;
  82. }
  83. function hidden() {
  84. state.hidden = true;
  85. tarH = 0;
  86. interval = setInterval(move,10);
  87. }
  88. function hiddenS() {
  89. head.style.borderBottom = \"none\";
  90. head.onmouseout = mouseout;
  91. head.onmouseout();
  92. content.style.display = \"none\";
  93. isOpen = false;
  94. state.hidden = false;
  95. }
  96. function move() {
  97. var dist = (tarH - content.style.height.pxToNum())*speed;
  98. if (Math.abs(dist) < 1) dist = dist > 0 ? 1: -1;
  99. content.style.height = (content.style.height.pxToNum() + dist) + \"px\";
  100. if (Math.abs(content.style.height.pxToNum() - tarH) <= range ) {
  101. clearInterval(interval);
  102. content.style.height = tarH + \"px\";
  103. if (tarH != 0) {
  104. showS()
  105. } else {
  106. hiddenS();
  107. }
  108. }
  109. }
  110. }
  111. var $ = function($) {return document.getElementById($)};
  112. String.prototype.pxToNum = function() {return Number(this.replace(\"px\",\"\"))}
  113. function getFirstChild(obj) {
  114. var result = obj.firstChild;
  115. while (!result.tagName) {
  116. result = result.nextSibling;
  117. }
  118. return result;
  119. }
  120. function getNextChild(obj) {
  121. var result = obj.nextSibling;
  122. while (!result.tagName) {
  123. result = result.nextSibling;
  124. }
  125. return result;
  126. }
  127. //]]>
  128. </script>
  129. <body>
  130. <ul class=\"rolinList\" id=\"rolin\">
  131. <li>
  132. <h2>花郎徒结</h2>
  133. <div class=\"content\"><p>当时明月在,曾照彩云归<br /><br />
  134. 倦了红颜,憔悴为千年,几多情深夜语,一点听风悠然。<br />
  135. 村忆梦回,飘逸如烟,友别怜影单。<br />
  136. 而今沙漠风闲,雪原清冷,东海云淡,石谷谁惜缘。<br />
  137. 累了心间,问也还烦,都道风沙淘尽,何日再慰别缘! </p></div>
  138. </li>
  139. <li>
  140. <h2>帝王槌</h2>
  141. <div class=\"content\"><p>立剑赏月意惆怅,袖饰刀,衣披霜,傲视雾丸,徒手战扶桑.<br />
  142. 问津终寻帝王陵,黑影没,尸满岗,惟见逆鲮露寒光.  <br />
  143. 须发苍,气轩昂,三尺银狼,破风动八方.  <br />
  144. 依身紧握噬魂枪,饮虎血,豪万丈.惟有千年我故乡!</p></div>
  145. </li>
  146. <li>
  147. <h2>玉女枪法</h2>
  148. <div class=\"content\"><p>曾经有个梦想:驰骋江湖,快意恩仇。<br />
  149. 曾经有份愿望:千里追凶,十步溅血。<br />
  150. 曾经有腔豪情:奇功盖世,名冠武林。<br />
  151. 曾经有种期盼:烛影摇红,衣袖添香。</p></div>
  152. </li>
  153. <li>
  154. <h2>黑沙刚体</h2>
  155. <div class=\"content\"><p>赵客缦胡缨,吴钩霜雪明。银鞍照白马,飒沓如流星。 <br />
  156. 十步杀一人,千里不留行。事了拂衣去,深藏身与名。 <br />
  157. 闲过信陵饮,脱剑膝前横。将炙啖朱亥,持觞劝侯嬴。 <br />
  158. 三杯吐然诺,五岳倒为轻。眼花耳热后,意气素霓生。 <br />
  159. 救赵挥金锤,邯郸先震惊。千秋二壮士,烜赫大梁城。 <br />
  160. 纵死侠骨香,不惭世上英。谁能书阁下,白首太玄经。</p>
  161. </div>
  162. </li>
  163. <li>
  164. <h2>不羁浪人枪</h2>
  165. <div class=\"content\"><p>素手相牵,斜辉入眼帘,一轮逍遥自在间,醉了山水闲。<br />
  166. 沙漠绿水涟,鱼游浅底,明眸一水天。<br />
  167. 爱在村友相谈,开心点点,笑语连连,率性夜无眠。<br />
  168. 月在西边,风乱星寒,辗转醇香旧事,蛾儿曼舞灯前。</p></div>
  169. </li>
  170. <li>
  171. <h2>雾水掌</h2>
  172. <div class=\"content\"><p>蹄影善奔,如幻如魔,其皮传世,绝学再现,<br />
  173. 又有谁在这残阳道中追逐它的身影... </p>
  174. </div>
  175. </li>
  176. </ul>
  177. </body>
  178. </html>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29737856/viewspace-1304319/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 文字滚动特效
请登录后发表评论 登录
全部评论

注册时间:2014-07-04

  • 博文量
    95
  • 访问量
    122213