zoukankan      html  css  js  c++  java
  • 公告滚动显示插件

    公告滚动显示插件(jQuery插件编写)

    插件代码:

    /**
    * 2014年11月13日
    * 公告滚动显示插件
    */
    
    (function ($) {
        $.fn.scrollNews = function (width) {
            if (this.find("li").length == 0) return;
    
            var ulWidth = 0;
            var currentMarginLeft = 0;
            var scrollStart = true;
    
            //初始化div属性
            this.parent().width(width);
            this.parent().css("overflow", "hidden");
    
            //初始化ul属性
            this.css("float", "left");
    
            //初始化li属性
            var liMarginRight = 20;
            this.find("li").css("margin-right", liMarginRight.toString() + "px");
            this.find("li").css("float", "right");
    
            //初始化ul宽度和当前的margin-left
            this.find("li").each(function () {
                ulWidth += $(this).width() + liMarginRight + 1;
            });
            this.width(ulWidth);
            currentMarginLeft = width;
            this.css("margin-left", currentMarginLeft);
    
            //滚动方法定义
            var scroll = function (obj) {
                setInterval(function () {
                    if (scrollStart) {
                        obj.css("margin-left", currentMarginLeft.toString() + "px");
                        currentMarginLeft -= 1;
                        if (currentMarginLeft < -ulWidth) currentMarginLeft = width;
                    }
                }, 50);
            };
    
            //显示div
            this.parent().css("visibility", "visible");
    
            //调用滚动方法
            scroll(this);
    
            this.mouseover(function () {
                scrollStart = false;
            });
    
            this.mouseout(function () {
                scrollStart = true
            });
        };
    })($);
    View Code

    示例HTML代码:

        <div style="float: right; margin-right: 10px; margin-top: 5px; font-size: 15px; visibility: hidden;">
            <ul id="ulgg">
                <!-- BEGIN noticeList -->
                <li><a href="#{noticeLink}"><span style="color: #ff0000;">★#{notice.NoticeTitle}</span></a></li>
                <!-- END noticeList -->
            </ul>
        </div>
    View Code

    示例JS代码:

        $(function () {
            $("#ulgg").scrollNews(450);
        });
    View Code
  • 相关阅读:
    SpringBoot 项目 打包为 Docker镜像
    0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.
    注册k8s到rancher时 agent pods一直处于containercreating状态
    linux查看磁盘使用情况
    linux修改系统时间、时区
    windows 添加路由
    Notebook Docker 安装spark环境
    openlayers6加载天地图混乱问题
    Oracle 高效分页
    VSCode 终端无法打开
  • 原文地址:https://www.cnblogs.com/s0611163/p/4095323.html
Copyright © 2011-2022 走看看