大概形如 部分... 展开全文 全文 然後就可以简单的操作了 比如 jQuery(document).delegate('.expand','click',function(){ var T = $(this);T.prev().hide()T.next().show()})...
类似豆瓣评论长文展开全文,收起的代码如何实现
然而你不知道的是, 大多数站点都是直接後台生成摺叠部分与全文的
大概形如
<div>部分...</div>
<a/button class="expand">展开全文</a/button>
<div/textarea>全文</div/textarea>
然後就可以简单的操作了
比如
jQuery(document).delegate('.expand','click',function()
{
var T = $(this);
T.prev().hide()
T.next().show()
})2015-08-25
不知道 你要的是不是这种效果 jquery.min.js文件不要忘了
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<title></title>
<meta charset="utf-8">
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var oldHeight=$("#box").height();
$("#box").css({height:"100px"});
$(".showa").click(function(){
if(parseInt($("#box").height())==oldHeight){
$("#box").animate({height:"100px"});
$(this).html("展开");
}else{
$("#box").animate({height:oldHeight});
$(this).html("收起");
}
});
});
</script>
</head>
<body>
<div id="box" style="background:#98bf21;width:300px;margin:6px;line-height:20px;text-overflow:ellipsis;
overflow:hidden">
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
</div>
<a href="javascript:void(0)" class="showa">展开</a>
</body>
</html>2015-08-25
jQuery的animate()方法对div自定义动画效果2015-08-25