1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <title>Document</title>
    5. <meta charset="utf-8" />
    6. <style type="text/css">
    7. *,body{
    8. margin:0;
    9. padding:0;
    10. }
    11. #view{
    12. width:500px;
    13. height:400px;
    14. background-color:#000;
    15. overflow:hidden;
    16. }
    17. #view_box{
    18. width:500px;
    19. height:400px;
    20. background-color:#ddd;
    21. background:url("res/htmlLX/lianxi1.jpg");
    22. }
    23. #cont{
    24. color:#fff;
    25. width:496px;
    26. height:50px;
    27. line-height:50px;
    28. position:relative;
    29. border:2px solid #191970;
    30. top:50px;
    31. font-size:20px;
    32. font-weight:bold;
    33. }
    34. #content{
    35. display:block;
    36. position:relative;
    37. top:0;
    38. }
    39. .btn{
    40. width:60px;
    41. height:30px;
    42. cursor:pointer;
    43. }
    44. </style>
    45. </head>
    46. <body >
    47. <div id="view">
    48. <div id="view_box">
    49. <div id="cont">
    50. <span id="content">文字横向移动效果,简单漂亮!!!</span>
    51. </div>
    52. </div>
    53. </div>
    54. <script type="text/javascript">
    55. var left = 0;// content的左边距
    56. function move(){
    57. // 补全代码,使文字向右移动
    58. left += 2;
    59. if(left>500){
    60. left = -300;
    61. }
    62. document.getElementById("content").style.left = left+"px";
    63. window.requestAnimationFrame(move);
    64. }
    65. move();
    66. </script>
    67. </body>
    68. </html>

    2021-09-26_163114.jpg2021-09-26_163124.jpg