·设为首页收藏本站📧邮箱修改🎁免费下载专区📒收藏夹👽聊天室📱AI智能体
返回列表 发布新帖

代码修改求助

218 1
发表于 2021-9-12 19:22:25 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
<style type="text/css">
.effshadow
{
  position: relative;
}
.effshadow:after
{
z-index: -1;
position: absolute;
content: "";
top: 15px;
left: 8px;
right: auto;
width: 50%;
height: 10%;
bottom: 80%;
max-width: 300px;
  background: #777;
  -webkit-box-shadow: 0 15px 10px #777;
  -moz-box-shadow: 0 15px 10px #777;
  box-shadow: 0 15px 10px #777;
  -webkit-transform: rotate(183deg);
  -moz-transform: rotate(183deg);
  -o-transform: rotate(183deg);
  -ms-transform: rotate(183deg);
  transform: rotate(183deg);
}  
.effbox h1{
        text-align:left;
        height:25px;
        line-height:25px;
        position:relative;
        top:0px;
        color:#009ad9;
        font:20px/1.5 Tahoma,'Microsoft Yahei','Simsun';
        float:left;
         margin:0px;
}
.effbox h3{
        text-align:center;
        position:relative;
        font:12px/1.5 Tahoma,'Microsoft Yahei','Simsun';
         margin:0px;
         height:30px;
}
.effbox {
        width:319px;
        height:37px;
        background:#FFF;
}
.shadowcon { width:100%; height:25px; margin:6px 5px 6px 10px; overflow:hidden;}
#rollBox{ height:25px; width:255px; overflow:hidden;list-style:none; margin:0; padding:0; position:relative; padding-left:5px; margin:50px auto; background:#FFf; cursor:pointer;}
.shadowcon li { list-style:none; line-height:25px; text-align:left;}
</style>
<div class="effbox">
<div class="effbox effshadow">
        <div class="shadowcon">
        <h3>
    <ul style="margin:5px 0 0 0;" id="rollBox">
    [loop]
    <li><a href="{url}" title="{title}"{target}>{title}({starttime})</a></li>
    [/loop]
    </ul>
    </h3></div></div></div>
   <script type="text/javascript">
var rollText={
        go:null,
        oParentUl:null,
        oUlH:null,
        liArr:null,
        childNode:null,
        timeout:null,
        run:function(id,delay){
                var oLiFirst=this.liArr[0];
                var liMarTop = oLiFirst.style.marginTop;
                var liTopNum=parseInt(liMarTop);
                var c = Math.abs(liTopNum);
                if(c< parseInt(this.oUlH)){
                        c++;
                        oLiFirst.style.marginTop ='-' + c + 'px';
                }else if(Math.abs(liTopNum)== parseInt(this.oUlH)){
                        clearInterval(this.go);
                        this.oParentUl.removeChild(oLiFirst);
                        this.oParentUl.appendChild(oLiFirst);
                        this.liArr[this.liArr.length-1].style.marginTop='0px';
                        this.timeout=setTimeout(function(obj,id,childtags,delay){return function(){obj.start(id,childtags,delay);};}(this,id,this.childNode,delay),delay);
                }

        },
        start:function(id,childtags,delay){

                this.childNode=childtags;
                this.oParentUl=document.getElementById(id);
                this.oUlH=this.oParentUl.currentStyle?this.oParentUl.currentStyle['height']:window.getComputedStyle(this.oParentUl,null)['height'];
                this.liArr=this.oParentUl.getElementsByTagName(childtags);
                for(var i=0;i<this.liArr.length;i++){
                        this.liArr<i>.style.cssText +=';margin-top:0;height:'+this.oUlH+';line-height:'+this.oUlH+';display:block; width:100%;';

                }
                this.go =setInterval(
                         function(obj,id,delay){
                        return function(){obj.run(id,delay)}
                }(this,id,delay),100);
                this.oParentUl.onmouseover=function(obj){return function(){clearTimeout(obj.timeout);clearTimeout(obj.go);};}(this);
                this.oParentUl.onmouseout=function(obj){return function(){obj.go =setInterval(function(obj,id,delay){return function(){obj.run(id,delay)};}(obj,id,delay),100);};}(this);

        }
}
rollText.start('rollBox','li',3000);
function clone(){};
clone.prototype= rollText;
</script>



请问各位大神,这段代码如何修改才能让他最多能显示出5行数据,现在只能显示1行,应该调一下哪些数字大小?

小白一个,不懂代码,求大神帮忙修改一下吧
我要说一句 收起回复

评论1

Discuz智能体Lv.8 发表于 2025-3-21 02:11:14 | 查看全部
你提供的代码片段主要涉及CSS样式和一些JavaScript代码,用于实现一个带有阴影效果的滚动文本区域。以下是对代码的详细解释和一些可能的改进建议:

### CSS部分

1. **`.effshadow` 类**:
   - 这个类用于创建一个带有阴影效果的元素。通过 `:after` 伪元素来实现阴影效果。
   - `position: relative;` 使得伪元素可以相对于该元素进行定位。
   - `:after` 伪元素设置了阴影的位置、大小、颜色和旋转角度。

2. **`.effbox h1` 和 `.effbox h3`**:
   - 这些样式定义了 `.effbox` 容器内的标题样式。
   - `h1` 和 `h3` 分别设置了不同的字体大小、颜色、对齐方式等。

3. **`.effbox` 类**:
   - 定义了一个固定宽度和高度的容器,背景为白色。

4. **`.shadowcon` 类**:
   - 定义了一个宽度为100%、高度为25px的容器,设置了外边距和溢出隐藏。

5. **`#rollBox`**:
   - 这是一个ID选择器,定义了一个高度为25px、宽度为255px的滚动区域,设置了溢出隐藏、列表样式、内边距和外边距。

6. **`.shadowcon li`**:
   - 定义了列表项的样式,去除了默认的列表样式,设置了行高和文本对齐方式。

### JavaScript部分

1. **`rollText` 对象**:
   - 这个对象用于实现文本的滚动效果。
   - `go`、`oParentUl`、`oUlH`、`liArr`、`childNode`、`timeout` 是对象的属性,用于存储滚动相关的DOM元素和定时器。
   - `run` 方法用于实现文本的滚动逻辑。它通过改变 `marginTop` 的值来实现文本的滚动效果。
   - `start` 方法用于初始化滚动效果,获取相关的DOM元素并启动滚动。

### 改进建议

1. **CSS优化**:
   - 可以考虑将一些重复的样式合并,减少代码冗余。
   - 使用CSS变量来管理颜色、字体等常用样式,方便后续维护。

2. **JavaScript优化**:
   - 可以将 `rollText` 对象的属性和方法封装得更清晰,避免全局变量的污染。
   - 使用 `requestAnimationFrame` 代替 `setTimeout` 来实现更流畅的动画效果。

3. **兼容性**:
   - 确保代码在现代浏览器和旧版浏览器中都能正常工作。可以使用Babel等工具进行代码转换。

### 示例代码优化

  1. .effshadow {
  2.   position: relative;
  3. }

  4. .effshadow:after {
  5.   z-index: -1;
  6.   position: absolute;
  7.   content: "";
  8.   top: 15px;
  9.   left: 8px;
  10.   width: 50%;
  11.   height: 10%;
  12.   background: #777;
  13.   box-shadow: 0 15px 10px #777;
  14.   transform: rotate(183deg);
  15. }

  16. .effbox h1, .effbox h3 {
  17.   margin: 0;
  18.   font-family: Tahoma, 'Microsoft Yahei', 'Simsun';
  19. }

  20. .effbox h1 {
  21.   text-align: left;
  22.   height: 25px;
  23.   line-height: 25px;
  24.   color: #009ad9;
  25.   font-size: 20px;
  26.   float: left;
  27. }

  28. .effbox h3 {
  29.   text-align: center;
  30.   font-size: 12px;
  31.   height: 30px;
  32. }

  33. .effbox {
  34.   width: 319px;
  35.   height: 37px;
  36.   background: #FFF;
  37. }

  38. .shadowcon {
  39.   width: 100%;
  40.   height: 25px;
  41.   margin: 6px 5px 6px 10px;
  42.   overflow: hidden;
  43. }

  44. #rollBox {
  45.   height: 25px;
  46.   width: 255px;
  47.   overflow: hidden;
  48.   list-style: none;
  49.   margin: 50px auto;
  50.   padding-left: 5px;
  51.   background: #FFF;
  52.   cursor: pointer;
  53. }

  54. .shadowcon li {
  55.   list-style: none;
  56.   line-height: 25px;
  57.   text-align: left;
  58. }
复制代码

  1. var rollText = {
  2.   go: null,
  3.   oParentUl: null,
  4.   oUlH: null,
  5.   liArr: null,
  6.   childNode: null,
  7.   timeout: null,

  8.   run: function(id, delay) {
  9.     var oLiFirst = this.liArr;
  10.     var liMarTop = oLiFirst.style.marginTop;
  11.     var liTopNum = parseInt(liMarTop);
  12.     var c = Math.abs(liTopNum);

  13.     if (c < parseInt(this.oUlH)) {
  14.       c++;
  15.       oLiFirst.style.marginTop = '-' + c + 'px';
  16.     } else if (Math.abs(liTopNum) == parseInt(this.oUlH)) {
  17.       clearInterval(this.go);
  18.       this.oParentUl.removeChild(oLiFirst);
  19.       this.oParentUl.appendChild(oLiFirst);
  20.       this.liArr.style.marginTop = '0px';
  21.       this.timeout = setTimeout(function(obj, id, childtags, delay) {
  22.         return function() {
  23.           obj.start(id, childtags, delay);
  24.         };
  25.       }(this, id, this.childNode, delay), delay);
  26.     }
  27.   },

  28.   start: function(id, childtags, delay) {
  29.     this.childNode = childtags;
  30.     this.oParentUl = document.getElementById(id);
  31.     this.oUlH = this.oParentUl.currentStyle ? this.oParentUl.currentStyle : window.getComputedStyle(this.oParentUl, null);
  32.     this.liArr = this.oParentUl.getElementsByTagName(childtags);
  33.     for (var i = 0; i < this.liArr.length; i++) {
  34.       // 初始化逻辑
  35.     }
  36.     this.go = setInterval(this.run.bind(this, id, delay), 20);
  37.   }
  38. };
复制代码


希望这些解释和建议对你有所帮助!如果你有更多问题,欢迎继续提问。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐

点我👉扫码添加站长微信,获取即时帮助!
点我👉扫码添加站长微信,获取即时帮助!
遇到问题别担心,添加站长微信,第一时间为您解决!专属客服在线等,享受一对一服务!

查看 »

AI智能体
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图

您的IP:3.21.41.164,GMT+8, 2025-4-12 03:57 , Processed in 0.356629 second(s), 79 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2025 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服
快速回复 返回顶部 返回列表