您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Jquery 高亮显示文本中重要的关键字_jquery

2024/6/1 6:12:45发布36次查看
一、界面预览
鼠标放到右边的tab按钮上,文字透明度降低,同时一段文字高亮显示,效果如下:
demo地址:http://5thirtyone.com/sandbox/samples/fadefocus/
  很绚丽的效果幺!
二、实现原理 
  将要高亮显示的文字加上段落标记, class=”mask”的div 做为遮罩层,使此遮罩层位于文字内容之上(z-index属性,使用jquery给段落动态添加样式类。
三、html代码
复制代码 代码如下:
summary
avatar
formats
avatar (2009 film)
avatar, also known as james cameron's avatar, is an american 3-d science fiction
epic film written and directed by
james cameron, and was released on december 16, 2009 by 20th century fox.
the film is co-produced by
lightstorm entertainment, and focuses on an epic conflict on pandora,
an inhabited earth-sized moon of polyphemus, one of three fictional gas giants orbiting
alpha centauri a. on
pandora, human colonists and the sentient humanoid indigenous inhabitants of pandora,
the na'vi, engage in a war over the planet's resources and the latter's continued
existence. the film's title refers to an avatar, a representation of
a real person in a virtual world.
the film was released in 2d and 3d formats, along with an
imax 3d release in selected theaters. the film is being touted as a breakthrough
in terms of filmmaking technology, for its development of 3d viewing and stereoscopic
filmmaking with cameras that were specially designed for the film's production.
read the rest of the original
wikipedia page about avatar
entity-results类中显示了tab按钮,每个按钮控制左边文字的透明度,段落文字的高亮显示。
entity-source类中有三个段落span calss分别为 d1 d2 d3,也就是高亮文字段落。
class=”mask”的空div放到最后,此div也就是一个遮罩层。
四、css关键代码
复制代码 代码如下:
.entity-source, .entity-source span.show
{
position: relative;
}
.entity-source .mask
{
display: none;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: 1;
}
.entity-source span
{
z-index: 2;
}
.entity-source span.show
{
background: #ffc;
color: #000;
}
类mask中的z-index:1 使得 覆盖在左边文字内容之上。
z-nidex:2又使得span段落覆盖在之上。从而显示实现了段落文字高亮显示。
五、jquery代码
复制代码 代码如下:
jquery(document).ready(function($) {
// mask source 控制mask的动画效果
var masksource = jquery('.mask');
jquery('.entity-results').hover(function() {
masksource.animate({opacity:0.7},1).fadein('750');
}, function() {
masksource.fadeout('1000');
});
// match hover 控制段落的高亮显示
var sample1 = jquery('span.d1');
var sample2 = jquery('span.d2');
var sample3 = jquery('span.d3');
jquery('a.d1').hover(function() {
sample1.addclass('show'); //给段落添加类
}, function() {
sample1.removeclass('show'); //移除段落类
});
jquery('a.d2').hover(function() {
sample2.addclass('show');
}, function() {
sample2.removeclass('show');
});
jquery('a.d3').hover(function() {
sample3.addclass('show');
}, function() {
sample3.removeclass('show');
});
});
动画函数animate(params, [duration], [easing], [callback])
params:一组包含作为动画属性和终值的样式属性和及其值的集合
duration (可选):种预定速度之一的字符串(slow, normal, or fast)或表示动画时长的毫秒数值(如:1000)
easing (可选):要使用的擦除效果的名称(需要插件支持).默认jquery提供linear 和 swing.
callback (可选):在动画完成时执行的函数
淡入效果函数:fadein(speed, [callback])
speed:三种预定速度之一的字符串(slow, normal, or fast)或表示动画时长的毫秒数值(如:1000)
callback (可选):(optional) 在动画完成时执行的函数
淡出效果函数:fadeout解释同fadein
演示地址:http://demo.jb51.net/html/fadefocus/index.html
打包下载地址: http://xiazai.jb51.net/200912/yuanma/fadefocus.rar
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product