Step 2: Define CSS style
Next, we need to define CSS style to beautify the scrolling prompt box. The specific style can be customized according to your own needs. The following example is for reference only:
#scrolling-box { width: 400px; height: 200px; overflow: hidden; position: relative; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } #content { position: absolute; width: 100%; height: 100%; top: 0; left: 0; display: flex; align-items: center; justify-content: center; animation: scroll 10s linear infinite; } @keyframes scroll { 0% { transform: translateY(0); } 100% { transform: translateY(-100%); } }
In the above code, we use the animation properties of CSS to achieve the scrolling effect. The transform attributes of the initial state and the end state are set in the animation @keyframes, and the scrolling effect is achieved by gradually changing the vertical displacement.
Step 3: Add jQuery code
Finally, we use jQuery to dynamically add or modify the content in the scrolling prompt box. First, we need to introduce the jQuery library, and then write the following code:
$(document).ready(function() { // 添加内容到滚动提示框 $('#content').append('<p>这是一条示例提示信息。</p>'); // 修改滚动提示框的样式 $('#scrolling-box').css('background-color', '#f5f5f5'); });
In the above code, we use jQuery's .ready() function to ensure that the document is loaded before executing the code. You can select the content container and outer container of the scroll prompt box through the selector, and use the .append() function to add content and the .css() function to modify the style.
Summary:
Through the combination of HTML, CSS and jQuery, we can easily build a beautiful scrolling prompt box. Just create the HTML structure, define CSS styles and use jQuery to add content and modify styles. In actual development, you can make style adjustments and functional expansion according to your own needs. I hope this article helps you build a satisfying scrolling tooltip.