以下是 jquery段落文字内容高亮显示js代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!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=utf-8" />
<title>jquery段落文字内容高亮显示</title>
<script type="text/javascript" src="js/jquery.1.4.2-min.js"></script>
</head>
<body>
<div class="headeline"></div>
<!--演示内容开始-->
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
a{color:#900;text-decoration:none;background:#fff0f0;}
a,.entity-source span{padding:0 2px;margin:0 -2px;}
a:hover{background:#ffd8d8;}
body{font:12px/180% helvetica,arial,sans-serif, "新宋体";background:#eee;color:#333;}
/* wrapper */
.wrapper{background:#fff;}
.wrapper,.content img{border:1px solid #ccc;border-left-color:#aaa;border-bottom-color:#aaa;}
.wrapper{width:520px;margin:60px auto;padding:25px 0 10px;}
/* content */
.content{width:360px;margin:0 0 0 20px;}
.content h2{font-size:21px;margin:0 0 10px}
.content p{margin:0 0 15px;line-height:18px}
.content img{float:left;padding:2px;margin:4px 10px 0 0;}
/* entity-results */
.entity-results{float:right;margin:0 -10px 0 0;}
.entity-results li{margin-bottom:2px;}
.entity-results a{background:#900;color:#eee;line-height:28px;width:120px;padding-left:7px;display:block;}
.entity-results a:hover{background:#5c0000;}
/* entity-source */
.entity-source .mask{display:none;position:absolute;top:0;left:0;height:100%;width:100%;z-index:1;background:#fff;}
.entity-source span{z-index:2;}
.entity-source span.show{background:#ffc;color:#000;}
.entity-source,.entity-source span.show{position:relative;}
</style>
<script type="text/javascript">
$(document).ready(function($) {
var maskSource = $('.mask');
$('.entity-results').hover(function(){
maskSource.animate({opacity:0.7},1).fadeIn('750');
},function(){
maskSource.fadeOut('1000');
});
var sample1 = $('span.d1');
var sample2 = $('span.d2');
var sample3 = $('span.d3');
$('a.d1').hover(function(){
sample1.addClass('show');
},function(){
sample1.removeClass('show');
});
$('a.d2').hover(function(){
sample2.addClass('show');
},function(){
sample2.removeClass('show');
});
$('a.d3').hover(function(){
sample3.addClass('show');
},function(){
sample3.removeClass('show');
});
});
</script>
<div class="wrapper">
<ul class="entity-results">
<li><a class="d1" href="#">总结</a></li>
<li><a class="d2" href="#">阿凡达</a></li>
<li><a class="d3" href="#">格式</a></li>
</ul>
<div class="content">
<h2>“阿凡达”Avatar(2009年电影)</h2>
<div class="entity-source">
<img src="images/avatar.jpg" alt="Avatar poster"/>
<p>“阿凡达”詹姆斯·卡梅隆的阿凡达,也被称为是美国的3-D科幻史诗电影编剧和导演詹姆斯·卡梅隆(James Cameron)由20世纪福克斯公司,并于2009年12月16日发布。这部电影是联合制作的Lightstorm娱乐, 和 <span class="d1">集中在一个史诗般的潘多拉星球上的冲突</span>,有人居住的地球大小的月亮的波吕斐摩斯,三个虚构的气态巨行星轨道的半人马座阿尔法星A的潘多拉,人类殖民者和众生的人形原居民,纳美人(潘多拉)之一,从事的战争在地球上的资源,而后者则继续存在。 这部电影的标题指的是 <span class="d2">阿凡达, 表示在虚拟世界中的一个真正的人</span>.</p>
<p><span class="d3">在2D和3D格式的影片上映</span>, 随着IMAX 3D版本在选定的剧院。这部影片被吹捧为电影制作技术方面取得突破性进展,其开发的三维可视摄像头,专为电影的制作和立体电影制作。</p>
<div class="mask"></div>
</div>
</div>
</div>
</body>
</html>