【发布时间】:2011-07-18 20:16:57
【问题描述】:
我有一个带有 jquery 显示/隐藏效果和“readmore”按钮的定义列表,一旦打开,它就会变为“关闭”。我现在需要在屏幕顶部为每个描述添加另一个引用锚点的按钮。当我尝试编辑脚本以添加新链接时,“返回页面顶部”按钮然后变成另一个“关闭”按钮。我在 JS 方面不够精通,无法编辑此脚本以使其执行我需要的操作而不会产生一些奇怪的后果。任何帮助表示赞赏。
SCRIPT
$(function(){
var slideHeight = 36;
$('.jswrap').each(function(){
var defHeight = $(this).height();
if(defHeight >= slideHeight){
$(this).css({'height':slideHeight,'max-height': defHeight});
$(this).after($('<div class="jsreadmore"><a href="#">Read More</a></div>'));
}
});
$('.jsreadmore a').click(function(){
var $targetSlide = $(this).parent().prev(),
curHeight = $targetSlide.height(),
defHeight = $targetSlide.css('max-height');
if(curHeight == slideHeight){
$targetSlide.animate({
height: defHeight
}, "normal");
$targetSlide.next().children('a').html('Close');
}else{
$targetSlide.animate({
height: slideHeight
}, "normal");
$targetSlide.next().children('a').html('Read More');
}
return false;
});
});
HTML
<div class="jscontainer">
<h4><a id="onedefinition">Definition Text</a></h4>
<div class="jswrap">
<p>content</p>
<p>morecontent</p>
</div></div>
CSS
.content_sub1 .jscontainer {margin:0 auto;}
.content_sub1 .jscontainer h2 {font-size:20px;color:#0087f1;}
.content_sub1 .jswrap {position:relative; padding:10px; overflow:hidden;}
.content_sub1 .jsgradient {width:100%;height:35px; position:absolute; bottom:0; left:0;}
.content_sub1 .jsreadmore {padding:5px; color:#333; text-align:right;}
.content_sub1 .jsreadmore a {padding-right:22px; font-weight:bold; font-size:12px; text-transform: uppercase; color:#c44; font-family:arial, sans-serif;}
.content_sub1 .jsreadmore a:hover {color:#000;}
链接
www.doctorhtiller.com/procedures.html
【问题讨论】:
标签: jquery hyperlink hide add show