JavaScript文本收缩展开 showdetail
原文发布时间为:2009-11-15 —— 来源于本人的百度文章 [由搬家工具导入]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<div id="divS" style="border:1px solid #f0f0f0;background-color:#ccc;padding:4px;margin:10px">
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
<p>测试</p>
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
<p>测试文本</p>
<p>测试了</p>
<p>测试侧试试了</p>
</div>
<p>
<script type="text/javascript"><!--
doShrink(document.getElementById('divS'),60);
function doShrink(oshrink,maxHeight){
if(oshrink){
var oH = (oshrink.clientHeight||oshrink.offsetHeight);
if(oH>maxHeight){
var linka = document.createElement("a");
var div = document.createElement("div");
div.innerHTML = "……<br />"
text = document.createTextNode("[点击查看更多内容]");
linka.href = "javascript:void(0)";
linka.onclick = function(e) { shrinkShow(this); }
linka.appendChild(text);
div.appendChild(linka);
var onext = oshrink.nextSibling;
if(onext)
oshrink.parentNode.insertBefore(div,onext);
else
oshrink.parentNode.appendChild(div);
//过滤较长的内容
oshrink.srcHeight = oH;
oshrink.style.cssText ="overflow-y: hidden; max-height: "+maxHeight+"px; *_height: "+maxHeight+"px; ";
}
}
}
function remove(o){
if(o && o.parentNode)o.parentNode.removeChild(o);
}
/* 第一种,具有展开效果 */
var shrinkInterval = false;
function shrinkShow(obj) {
var omore = obj.parentNode;
var ohide = omore.previousSibling;
shrinkInterval = window.setInterval(function(){shrinkStep(ohide);},20);
remove(omore); //去除更多链接
}
function shrinkStep(ohide){
var targetHeight = ohide.srcHeight;
var nowHeight = (ohide.clientHeight||ohide.offsetHeight);;
if(nowHeight < targetHeight){
ohide.style.height = nowHeight+20 + 'px';
ohide.style.maxHeight = nowHeight+20 + 'px';
}else{
if(shrinkInterval){
window.clearInterval(shrinkInterval);
shrinkInterval = false;
}
}
}
/* 第二种,没有展开效果 */
/*
function shrinkShow(obj) {
var omore = obj.parentNode;
var ohide = omore.previousSibling;
ohide.style.height = ohide.srcHeight + 'px';
ohide.style.maxHeight = ohide.srcHeight + 'px';
remove(omore); //去除更多链接
}
*/
// --></script>
</p>
</body>
</html>
JavaScript文本收缩展开 showdetail的更多相关文章
- jQuery文本段落展开和折叠效果
<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...
- JS 播放列表收缩展开
下面要做实现的效果 收缩和展的功能 遵循网页布局,行为,结构,样式 分离 下面是html 结构代码: <div id="drop" class="down_list ...
- jQuery 收缩展开效果
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...
- jQuery 文本段落展开和折叠效果
jQuery 文本段落展开和折叠效果 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" c ...
- javascript 文本框值变化触发事件
javascript 文本框值变化触发事件jo.find(".price").bind('input onpropertychange', function () { me.cal ...
- C#使用splitContainer控件制作收缩展开面板
C#使用splitContainer控件制作收缩展开面板 原创 2011年07月19日 17:18:02 标签: c# / object / 扩展 / 测试 15690 最近对Squi ...
- JS收缩展开效果
// 收缩展开效果 $(document).ready(function () { $(".box h2").toggle(function () { $(this).next(& ...
- 多个div的多文本部分展开显示+关键字自动标注
效果: 源码: <%@ page language="java" contentType="text/html; charset=utf-8" pageE ...
- JavaScript文本框焦点事件
效果图如下: <!-- 当文本框获得焦点时候,如果文本框内容是 请输入搜索关键字 清空文本框,输入内容变黑色 --> <!-- 当文本框失去焦点时候,如果文本框无内容,则添加灰色的 ...
随机推荐
- 【JAVA】mac配置java环境变量
如果用bash,修改~/.bash_profile 或 ~/.profile: 如果用zsh,修改-/.zshrc 修改这些文件之后,重修打开terminal,配置不会丢 首先确保已经安装了jdk: ...
- 12.1.VUE学习之-循环li,if判断示例讲解class中应用表达式
功能: 当点击按键时,改变当前循环数组里的status里的值, 判断staus里的当前的值来,切换显示 删除 和 恢复 的按钮 判断staus里的当前的值来改变span标签里的字体颜色样式 <! ...
- 免费证书Let’s Encrypt
我们自己也可以签发 SSL 安全证书,但是我们自己签发的安全证书不会被主流的浏览器信任,所以我们需要被信任的证书授权中心( CA )签发的安全证书.而一般的 SSL 安全证书签发服务都比较贵,比如 G ...
- Linux常见的系統进程
前言 在日常运维工作中,经常会看到一些奇怪的系统进程占用资源比较高.而且总是会听到业务线同学询问“xxx这个是啥进程啊?咋开启了这么多?” 而这些系统级的内核进程都是会用中括号括起来的,它们会执行一些 ...
- 51nod 1554 KMP思维题
题目为中文,因而不再解释题意. 首先遵循如下设定可以有以下几个结论:1,首先谈论下KMP的一个特殊性质:对于某一个特立独行的字符串:例如ABCDEF,在建立有限状态自动机之后,都会有,所有元素的失配边 ...
- [原]sencha touch之NavigationView
还是直接上代码,都是基本的几个容器控件,没什么还说的 Ext.application({ name:'itkingApp', launch:function(){ var view =Ext.crea ...
- 批处理文件执行cmd命令
@echo offstart "wumin" "C:\Windows\System32\cmd.exe" osk taskkill /f /im cmd.exe ...
- 第2章c++简单程序设计
第2章c++简单程序设计 知识梳理 以下是我遗忘以及认为重要的知识整理: 1.标识符的构成规则: 以大写字母.小写字母或下划线 _ 开始 由大写字母.小写字母.下划线 _ 或数字(0~9)组成 大写字 ...
- CART树 python小样例
决策树不断将数据切分成小数据集,直到所有目标变量完全相同,或者数据不能再切分为止,决策时是一种贪心算法,它要在给定的时间内做出最佳选择,但并不关心能否达到最优 树回归 优点:可以对复杂和非线性的数据建 ...
- XX公司在线笔试题编程题之一
题目: #include <iostream> #include <vector> #include <string> #include <list> ...