marguee实现最新公告动态轮播效果

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>最新公告动态轮播效果</title>
<link type="text/css" href="css/new_notice_lunbo.css" rel="stylesheet"/>  
</head>
<body>  
<div id="mar1">  
    <ul>  
        <li>测试数据第一条</li>  
        <li>测试数据第二条</li>  
        <li>测试数据第三条</li>  
        <li>测试数据第四条</li>  
        <li>测试数据第五条</li>  
        <li>测试数据第六条</li>  
    </ul>  
</div> 
<div id="mar2">  
    <ul>  
        <li>测试数据第一条</li>  
        <li>测试数据第二条</li>  
        <li>测试数据第三条</li>  
        <li>测试数据第四条</li>  
        <li>测试数据第五条</li>  
        <li>测试数据第六条</li>  
    </ul>  
</div>  
<div id="mar3">  
    <ul>  
        <li>测试数据第一条</li>  
        <li>测试数据第二条</li>  
        <li>测试数据第三条</li>  
        <li>测试数据第四条</li>  
        <li>测试数据第五条</li>  
    </ul>  
</div>  
<div id="mar4">  
    <ul>  
        <li>测试数据第一条</li>  
        <li>测试数据第二条</li>  
        <li>测试数据第三条</li>  
        <li>测试数据第四条</li>  
        <li>测试数据第五条</li>  
    </ul>  
</div>  
<div id="mar5">  
    <ul>  
        <li>测试数据第一条</li>  
        <li>测试数据第二条</li>  
        <li>测试数据第三条</li>  
        <li>测试数据第四条</li>  
        <li>测试数据第五条</li>  
    </ul>  
</div>  
<div id="mar6">  
    <ul>  
        <li>测试数据第一条</li>  
        <li>测试数据第二条</li>  
        <li>测试数据第三条</li>  
        <li>测试数据第四条</li>  
        <li>测试数据第五条</li>  
    </ul>  
</div>  
<script src="js/jquery-1.10.2.min.js"></script>  
<script src="js/new_notice_lunbo.js"></script> 
</body>  

</html>

js:

(function (jQuery) {  
   jQuery.fn.extend({  
       /**  
        *@description 无缝滚动支持匀速上下左右和垂直翻滚上下  
        *@param {  
         *      direction:string,//滚动方向 值域:top|left|bottom|right|up|down  
        *      speed:string//滚动速度(垂直翻滚时为停留时间)  
        * } o  
        *@example  
        *HTML结构  
        *<div id="mar">  
        *    <ul>  
        *        <li>内容1</li>  
        *        <li>内容2</li>  
        *        <li>内容3</li>  
        *    </ul>  
        *</div>  
        *mar样式应该包含height,width,background等 注意不要覆盖了插件附加上去的样式  
        *调用:  
        *jQuery("#mar").marquee({ 
        *    direction:"top",  
        *    speed:30  
        *})  
        *  
        */  
       marquee:function (o) {  
           var it = this,  
                   d = o.direction || 'left', //滚动方向 默认向左  
                   s = o.speed || 30, //速度 默认30毫秒  
                   mar = jQuery(it),  
                   mp1 = jQuery(it).children(0).attr({id:"mp1"}),  
                   marqueeFunc = getMarquee(d),  
                   marRun = marqueeFunc ? setInterval(marqueeFunc, s) : function () {  
                       return false;  
                   };//开始滚动  
           //鼠标悬停事件  
           jQuery(it).hover(function () {  
               clearInterval(marRun);  
           }, function () {  
               marRun = setInterval(marqueeFunc, s);  
           })  
           /*生成滚动函数  
            *1.判断方向 *2.装载CSS *3.判断需不需要滚动 *4.构造函数  
            */  
           function getMarquee(d) {  
               var marqueeFunc;  
               switch (d) {  
                   //水平向左  
                   case "left":  
                       mar.addClass("plus-mar-left");  
                       var liHeight = mar[0].offsetHeight;  
                       mar.css({"line-height":liHeight + "px"});  
                       if (mp1[0].offsetWidth < mar[0].offsetWidth) return false;  
                       mp1.clone().attr({id:"mp2"}).appendTo(mar);  
                       marqueeFunc = function () {  
                           if (mar[0].scrollLeft >= mp1[0].scrollWidth) {  
                               mar[0].scrollLeft = 0;  
                           } else {  
                               mar[0].scrollLeft++;  
                           }  
                       }  
                       break;  
                   //水平向上  
                   case "top":  
                       mar.addClass("plus-mar-top");  
                       if (mp1.outerHeight() <= mar.outerHeight()) return false;  
                       var mp2 = mp1.clone().attr({id:"mp2"}).appendTo(mar);  
                       marqueeFunc = function () {  
                           var scrollTop = mar[0].scrollTop;  
                           if (mp1[0].offsetHeight > scrollTop) {  
                               mar[0].scrollTop = scrollTop + 1;  
                           } else {  
                               mar[0].scrollTop = 0;  
                           }  
                       }  
                       break;  
                   //水平向右  
                   case "right":  
                       mar.addClass("plus-mar-left");  
                       var liHeight = mar[0].offsetHeight;  
                       mar.css({"line-height":liHeight + "px"});  
                       if (mp1[0].offsetWidth <= mar[0].offsetWidth) return false;  
                       var mp2 = mp1.clone().attr({id:"mp2"}).appendTo(mar);  
                       marqueeFunc = function () {  
                           if (mar[0].scrollLeft <= 0) {  
                               mar[0].scrollLeft += mp2[0].offsetWidth;  
                           } else {  
                               mar[0].scrollLeft--;  
                           }  
                       }  
                       break;  
                   //水平向下  
                   case "bottom":  
                       mar.addClass("plus-mar-bottom");  
                       if (mp1[0].offsetHeight <= mar[0].offsetHeight) return false;  
                       var mp2 = mp1.clone().attr({id:"mp2"}).appendTo(mar);  
                           mar[0].scrollTop = mar[0].scrollHeight;  
                           marqueeFunc = function () {  
                               if (mp1[0].offsetTop >= mar[0].scrollTop) {  
                                   mar[0].scrollTop += mp1[0].offsetHeight;  
                               } else {  
                                   mar[0].scrollTop--;  
 
                               }  
                           }  
                           break;  
                       //垂直翻滚 向上  
                   case "up":  
                       mar.addClass("plus-mar-up");  
                       var liHeight = mar[0].offsetHeight;  
                       mp1.css({"line-height":liHeight + "px"});  
                       marqueeFunc = function () {  
                           var currLi = it.eq(0).find("ul:first");  
                           currLi.animate({  
                               marginTop:-liHeight  
                           }, 500, function () {  
                               currLi.find("li:first").appendTo(currLi);  
                               currLi.css({marginTop:0});  
                           })  
                       }  
                       break;  
                   //垂直翻滚 向下  
                   case "down":  
                       mar.addClass("plus-mar-down");  
                       var liHeight = mar[0].offsetHeight,  
                               liLength = mp1.children().length,  
                               topInit = -(liLength - 1) * liHeight + "px";  
                       mp1.css({"top":topInit, "line-height":liHeight + "px"});  
                       marqueeFunc = function () {  
                           var currLi = it.eq(0).find("ul:last");  
                           currLi.animate({  
                               marginTop:liHeight  
                           }, 500, function () {  
                               currLi.find("li:last").prependTo(currLi);  
                               currLi.css({marginTop:0});  
                           })  
                       }  
                       break;  
                   default:  
                   {  
                       marqueeFunc = null;  
                       alert("滚动插件:传入的参数{direction}有误!");  
                       }  
                   }  
                   return marqueeFunc;  
               }  
           }  
       })  
   })(jQuery);  
   
   $("#mar1").marquee({  
   direction:"top",  
       speed:30  
   });  

   $("#mar2").marquee({  
   direction:"bottom",  
       speed:30  
   });  
 
   $("#mar3").marquee({  
   direction:"right",  
       speed:30  
   });  
 
   $("#mar4").marquee({  
   direction:"left",  
       speed:30  
   });  
 
   $("#mar5").marquee({  
   direction:"down",  
   speed:2000  
})  
$("#mar6").marquee({  
   direction:"up",  
   speed:3000  
}); 

css:

html{ overflow-y: auto;}
.plus-mar-left{overflow:hidden; word-break:keep-all; white-space:nowrap;}
.plus-mar-left ul{list-style:none; margin:0; padding:0; display:inline-block; *display:inline; zoom:1;}
.plus-mar-left li{display:inline-block; *display:inline; zoom:1; text-indent:15px;}


.plus-mar-top{overflow:hidden; word-break:keep-all; white-space:nowrap;}
.plus-mar-top ul{list-style:none; margin:0; padding:0;  line-height:40px;}
.plus-mar-top li{ padding-right:10px;}


.plus-mar-bottom{overflow:hidden; word-break:keep-all; white-space:nowrap; position:relative;}
.plus-mar-bottom ul{list-style:none; margin:0; padding:0;  line-height:40px; position:relative;}
.plus-mar-bottom li{ padding-right:10px;}


.plus-mar-up{overflow:hidden;}
.plus-mar-up ul{list-style:none; margin:0; padding:0;  line-height:40px;}


.plus-mar-down{overflow:hidden; position:relative;}
.plus-mar-down ul{list-style:none; margin:0; padding:0; position:relative;}
/*marquee插件的样*/
/*活动弹框统一样式*/
.tips-title{height:53px; line-height:53px;margin-left:20px; padding-top:4px; font-size:18px; font-weight:bold;font-family:"΢���ź�";}
.tips-cont{padding:0 0 20px 20px;clear:left; font-size:12px; line-height:23px;font-family:"΢���ź�";}
.box .party-box .box-ft{ text-align:left; margin:0 0 0 20px;}


body .box .box-content .box-ico { margin:0 15px 0 0; display: inline; }
body .box .box-content .tools .btn-box-ok span,body .box .box-ft .box-btn-bt .btn-box-ok span{_width:60px;}


/*活动充值弹*/
.box .box-noCharge .box-noCharge-content .box-ft{ text-align: center;}
/*活动弹框统一样?*/
        #mar1 { height: 120px; width: 200px; margin-top: 20px; margin-left: 20px; background: #333; color: #FFF; }  
        #mar2 { height: 120px; width: 200px; margin-top: 20px; margin-left: 20px; background: #333; color: #FFF; }  
        #mar3 { height: 40px; width: 500px; margin-top: 20px; margin-left: 20px; background: #06F; color: #FFF; }  
        #mar4 { height: 40px; width: 500px; margin-top: 20px; margin-left: 20px; background: #06F; color: #FFF; }  
        #mar5 { height: 40px; width: 500px; margin-top: 20px; margin-left: 20px; background: #F66; color: #FFF; }  
        #mar6 { height: 40px; width: 500px; margin-top: 20px; margin-left: 20px; background: #F66; color: #FFF; } 








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值