每隔一段时间 文字的滚动

此博客展示了一个包含公告和滚动图片的网页布局,通过JavaScript实现左右箭头滚动效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
 
 
<script language="javaScript" src="scrollpic.js" charset="utf-8"></script>
<script language="javaScript" src="jquery_last.js" charset="utf-8"></script>
 
 <style type="text/css">
 .pic_top div{float:left}
    .pic_yi{height:80px; width:87px;vertical-align:middle;}
    .pic_center a{color:#173969;font-size:12px;}
    .pic_center img{margin-left:18px}
    </style>
   
 <style type="text/css">
    .text_top div{float:left}
    .text_yi{height:80px;_height:35px; width:600px;padding-top:1px}
    </style>
 
 
 
</head>
 
<body  >
 
 
 
<!-- 上左 -->
    <div class="text_top" style="float:left;height:34px;line-height:34px;width:700px;border:1px solid #DDDDDD;background-color:#F5F5F5;margin-top:10px;">
       <div style="float:left"><strong><font style="font-size: 15px;">&nbsp;&nbsp;&nbsp;公告:</font></strong>
       </div>
       <div class="pic_center" id="divAcrollPic2" style=" overflow:hidden; font-size:12px;color:#999999;">
     <div class="text_yi"><font style="font-size: 12px;"color="#555555">&nbsp;&nbsp;<a href="https://www.bestpay.com.cn/LeftFeeIndex/LeftAppIndex.html" style="color: #555555" target="_blank">最新开通济南、重庆、宁波、上海金山缴水费,更多城市陆续开通中...</a></font>
     </div>
     <div class="text_yi"><font style="font-size: 12px;"color="#555555">&nbsp;&nbsp;<a href="https://www.bestpay.com.cn/news/newsDetail.html?newId=1332" style="color: #555555" target="_blank">广东地区“翼支付惊喜大放送”手机客户端话费充值返利活动结束公告</a></font>
     </div>  
       </div>
       <div  id="Leftpic" style="cursor: pointer;width:19px;height:100%;margin-top:7px;_margin-top:3px;"><img id="img1" src="../images/new/left1.jpg"  />
       </div>
    <div  id="Rightpic" style="cursor: pointer;width:19px;height:100%;margin-top:7px;_margin-top:3px;"><img id="img2" src="../images/new/right1.jpg"  />
    </div>

<script type="text/javascript">
// 左右点击滚动开始
var scrollPic1 = new ScrollPic();
scrollPic1.scrollContId   = "divAcrollPic2"; //内容容器ID
scrollPic1.arrLeftId      = "Leftpic";//左箭头ID
scrollPic1.arrRightId     = "Rightpic"; //右箭头ID
 
scrollPic1.frameWidth     = 600;//显示框宽度
scrollPic1.pageWidth      = 600; //翻页宽度
 
scrollPic1.speed          = 9; //移动速度(单位毫秒,越小越快)
scrollPic1.space          = 90; //每次移动像素(单位px,越大越快)
scrollPic1.autoPlay       = true; //自动播放
scrollPic1.autoPlayTime   =0; //自动播放间隔时间(秒)
 
scrollPic1.initialize(); //初始化
// 左右点击滚动结束
</script>

</body>
</html>

 

### 使用 JavaScript 实现文本平滑无限循环滚动 为了创建一个具有平滑无限循环滚动效果的文字展示区,可以采用多种方法。一种常见的方式是利用 `setInterval` 函数来定时调整元素的位置属性,配合 CSS 的过渡效果使移动看起来更加自然[^1]。 下面是一个简单的例子,它通过改变容器内子项的定位样式来进行上下方向上的连续滚动: ```html <div id="scroll-container"> <div class="content">这是一些要滚动显示的信息...</div> </div> <style> #scroll-container { height: 100px; /* 容器高度 */ overflow: hidden; } .content { transition: transform .5s ease-in-out; } </style> <script> let container = document.getElementById('scroll-container'); let content = container.querySelector('.content'); function scrollText() { let topPosition = parseFloat(window.getComputedStyle(content).getPropertyValue("transform").split(',')[5]); if (topPosition <= -content.offsetHeight + container.offsetHeight) { // 当内容完全移出视口时重置位置 content.style.transform = 'translateY(0)'; } else { content.style.transform = `translateY(${topPosition - 2}px)`; // 向下微调像素数可自定义 } } // 设置间隔时间以控制速度 setInterval(scrollText, 30); </script> ``` 此段代码实现了基于浏览器窗口大小自动适应的高度设置,并且每当内容超出可见范围之后就会立即返回起始状态继续向下滚动,从而达到所谓的“无缝”体验。 对于更复杂的场景,比如水平滚动或是带有动画曲线的情况,则可能需要用到更多的 HTML/CSS/JS 技巧组合,甚至借助第三方库如 GSAP 来简化开发过程并增强性能表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值