首页 > 代码库 > JS配合css实现slide文字框缩放伸展效果
JS配合css实现slide文字框缩放伸展效果
<!DOCTYPE html><html><head><meta http-equiv="content" content="text/html charset=gb2312"><title>JS配合css实现slide文字框缩放伸展效果</title><style type="text/css">*{margin:0; padding:0;}ul{list-style:none;}.box{width:300px; margin:10px; border:1px solid #ccc; overflow:hidden; position:relative; font-size:12px;}.oHx{height:30px; background:#eee; line-height:30px; font-size:14px; text-indent:14px; cursor:pointer;}.fold{position:absolute; top:9px; right:12px;}.box_content{line-height:18px; overflow:hidden; display:none;}</style><script type="text/javascript"> function getElementsByClassName(className,id,tag){ tag = tag || "*"; if(id){ var id = typeof id == "string" ? $(id) : id; }else{ var id = document.body; } var els = id.getElementsByTagName(tag),arr = []; for(var i=0,n=els.length;i<n;i++){ for(var j=0,k=els[i].className.split(" "),l=k.length;j<l;j++){ if(k[j]==className){ arr.push(els[i]); break; } } } return arr; }; function Slide(slideClass,slideBtn,slideCon,slideSpeed) { this.oSlides = getElementsByClassName(slideClass); this.oTimer = null; this.slideBtn = slideBtn; this.slideCon = slideCon; this.slideSpeed = slideSpeed; } Slide.prototype = { oTimer:null, _init:function (){ this._slideEvent(); }, _slideEvent:function (){ var This = this; for(var i = 0,n=This.oSlides.length;i<n;i++){ (function(n){ var oSlide = This.oSlides[n]; var oSlideBtn = getElementsByClassName(This.slideBtn,oSlide)[0]; var oSlideCon = getElementsByClassName(This.slideCon,oSlide)[0]; oSlideBtn.onclick = function (){ if(oSlideCon.style.display == "block" && This.oTimer == null){ This._slideClose(oSlideCon); }else if(!(oSlideCon.style.display == "block" ) && This.oTimer == null){ This._slideOpen(oSlideCon); } } })(i) } }, _slideOpen:function (slideCon){ var This = this; slideCon.style.display = "block"; slideCon.style.height = "auto"; var slideHeight = slideCon.offsetHeight; slideCon.style.height = 0 + "px"; This.oTimer = setInterval(function (){ if(slideCon.offsetHeight < slideHeight){ slideCon.style.height = slideCon.offsetHeight + 2 + "px"; }else{ clearInterval(This.oTimer); This.oTimer = null; } },This.slideSpeed); }, _slideClose:function (slideCon){ var This = this; This.oTimer = setInterval(function (){ if(slideCon.offsetHeight <= 0){ clearInterval(This.oTimer); slideCon.style.display = "none"; This.oTimer = null; }else{ slideCon.style.height =slideCon.offsetHeight - 2 + "px"; } },This.slideSpeed); } } </script> </head> <body> <div class="box"> <div class="oHx slide">收缩1</div> <div class="box_content"> <ul class="uft" style="padding:10px;"> <li><a title="渐变彩色的文字" target="_blank" href="#">渐变彩色的文字</a></li><li><a title="指定文字逐条显示" target="_blank" href="#">指定文字逐条显示</a></li><li><a title="滚动的标题栏" target="_blank" href="#">滚动的标题栏</a></li><li><a title="JS 4屏平滑滚动幻灯片特效" target="_blank" href="#">JS 4屏平滑滚动幻灯片特效</a></li><li><a title="图片的无缝滚动(纵向、横向)" target="_blank" href="#">图片的无缝滚动(纵向、横向)</a></li><li><a title="鼠标触及带边框的菜单" target="_blank" href="#">鼠标触及带边框的菜单</a></li><li><a title="比较实用的CSS控制链接颜色效果" target="_blank" href="#">比较实用的CSS控制链接颜色效果</a></li> </ul> </div> </div> <div class="box"> <div class="oHx slide">收缩2</div> <div class="box_content"><li><a title="超级漂亮的几款清新、常用的网页CSS布局配色实例" target="_blank" href="#">超级漂亮的几款清新、常用的网页CSS布局配色实例</a></li><li><a title="CSS制作斜角上有背景图片的Div层" target="_blank" href="#">CSS制作斜角上有背景图片的Div层</a></li><li><a title="Js实现的层展开、层折叠效果,默认时候层是折叠的" target="_blank" href="#">Js实现的层展开、层折叠效果,默认时候层是折叠的</a></li><li><a title="DIV始终固定在网页右下角位置的CSS实现方法" target="_blank" href="#">DIV始终固定在网页右下角位置的CSS实现方法</a></li><li><a title="JavaScript未知高度元素的垂直居中的方法" target="_blank" href="#">JavaScript未知高度元素的垂直居中的方法-石家庄水泵厂-河北苗木</a></li><li><a title="渐变彩色的文字" target="_blank" href="#">渐变彩色的文字</a></li><li><a title="指定文字逐条显示" target="_blank" href="#">指定文字逐条显示</a></li><li><a title="滚动的标题栏" target="_blank" href="#">滚动的标题栏</a></li> </ul> </div> </div> <script type="text/javascript"> var mySlide = new Slide("box","slide","box_content",10); mySlide._slideEvent(); </script> </body></html>
JS配合css实现slide文字框缩放伸展效果
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。