html & js
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div id="flowing-text"> <h2>Flowing Text</h2> <div class="fix-box"> <div class="flowing-box"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div> </div> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> <script> $(function(){ var $flowText = $('#flowing-text'), $fixBox = $flowText.find('.fix-box'), $flowBox = $fixBox.find('.flowing-box'), flowbox_width = $flowBox.width(), flowTime=30000, easing = 'linear', right_start, right_running, timer; $flowBox.css({left:'100%'}); right_start = $flowBox.offset().left+flowbox_width; function flowingStart (){ if(!$flowBox.hasClass('stop')){ $flowBox.animate( {left: -flowbox_width}, flowTime, easing, function(){ $flowBox.css({left: '100%'}); } ); flowTime=30000; } else { $flowBox.stop(true, false); right_running=$flowBox.offset().left+flowbox_width; flowTime=Math.floor(((right_running)/right_start)*10000); } } function flowingMonitor(){ timer = setInterval(function(){ flowingStart(); },300); } $fixBox.on('mouseover',function(){ $flowBox.addClass('stop'); }) .on('mouseout',function(){ $flowBox.removeClass('stop'); }) flowingMonitor(); }); </script> </body> </html>
#flowing-text { margin:100px; } h2 { text-align:center; margin-bottom: 20px; } .fix-box { position: relative; height: 35px; box-shadow: 0px 0px 8px 3px #ccc inset; overflow: hidden; } .flowing-box { position: absolute; top: 5px; transform: translateY(-50%); } p { white-space: pre; }
OK 大体のイメージは掴めた
テキストをajaxでPOST&GETで取得して表示できるようにしたい