/*手机端菜单点击效果 */ $('.menu').click(function() { $(this).toggleClass('menu-active'); }); /*文本溢出显示省略号*/ function Dot(className,length) { var content_arr = [];//定义一个空数组 $(className).each(function(){//遍历box内容 var content = $.trim($(this).text());//去掉前后文空格 content_arr.push(content);//内容放进数组 }); for(var i = 0; i < content_arr.length; i++){//遍历循环数组 if(content_arr[i].length >= length){//如果数组长度(也就是文本长度)大于等于50(数字可自己定义) content = content_arr[i].substr(0,length)+'...';//添加省略号并放进box文字内容后面 $(className).eq(i).text(content); }else{ content=content_arr[i]; $(className).eq(i).text(content); } } }; function Overflow(className, rows, str){ var text = className; var oStyle = text.currentStyle ? text.currentStyle : window.getComputedStyle(text, null); var lineHeight; if (oStyle.getPropertyValue) { lineHeight = oStyle.getPropertyValue("line-height"); } else { lineHeight = oStyle.getAttribute("lineHeight"); } //获取到line-height样式设置的值 必须要有 var at = rows*parseInt(lineHeight); //计算包含文本的div应该有的高度 var tempstr = str; //获取到所有文本 text.innerHTML = tempstr; //将所有文本写入html中 var len = tempstr.length; var i = 0; if (text.offsetHeight <= at){ //如果所有文本在写入html后文本没有溢出,那不需要做溢出处理 } else { //否则 一个一个字符添加写入 不断判断写入后是否溢出 var temp = ""; text.innerHTML = temp; while(text.offsetHeight <= at){ temp = tempstr.substring(0, i+1); i++; text.innerHTML = temp; } var slen = temp.length; tempstr = temp.substring(0, slen-1); len = tempstr.length text.innerHTML = tempstr.substring(0, len-3) +"..."; //替换string后面三个字符 text.height = at +"px"; //修改文本高度 为了让CSS样式overflow:hidden生效 } }; function getByClass(node, className){ //如果浏览器支持 会得到一个函数体 if(node.getElementsByClassName){ return node.getElementsByClassName(className); } //把所有的元素获取到 var allItems = node.getElementsByTagName("*"); var newArr = []; //查找每一个元素的className 看其中含不含name for(var i = 0; i < allItems.length; i++){ var classNames = allItems[i].className; var arrClass = classNames.split(" "); for(var j = 0; j < arrClass.length; j++){ if(arrClass[j] == className){ newArr.push(allItems[i]); } } } return newArr; }; DlWidth(); $('.Nnav li').mouseenter(function() { $(this).find('dl').fadeIn(300); }).mouseleave(function() { $(this).find('dl').fadeOut(200); }); window.onresize = function() { DlWidth(); }; function DlWidth() { var WindowWidth = $(window).width(); $('.Nnav li').each(function() { var offLeft = $(this).offset().left; var dlWidth = WindowWidth - offLeft; $(this).find('dl').css('width', dlWidth); }) };