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



还是先看看效果再说吧:

呵呵。不错吧。

Demo地址:http://5thirtyone.com/sandbox/samples/fadefocus/

  很绚丽的效果幺!

二、实现原理

  将要高亮显示的文字加上段落标记, class=”mask”div 做为遮罩层,使此遮罩层位于文字内容之上(z-index属性,使用Jquery给段落动态添加样式类。

三、HTML代码

<div class="wrapper">

    <ul class="entity-results">

        <li><a class="d1" href="#">Summarya>li>

        <li><a class="d2" href="#">Avatara>li>

        <li><a class="d3" href="#">Formatsa>li>

    ul>

    <div class="content">

        <h2>

            Avatar (2009 film)h2>

        <div class="entity-source">

            <img src="images/avatar.jpg" alt="Avatar poster" />

            <p>

                Avatar, also known as James Cameron's Avatar, is an American 3-D science fiction

                epic film written and directed by <ahref="http://en.wikipedia.org/wiki/James_Cameron">

                    James Camerona>, and was released on December 16, 2009 by 20th Century Fox.

                The film is co-produced by <ahref="http://en.wikipedia.org/wiki/Lightstorm_Entertainment">

                    Lightstorm Entertainmenta>, and <span class="d1">focuses on an epic conflict on Pandoraspan>,

                an inhabited Earth-sized moon of Polyphemus, one of three fictional gas giants orbiting

                <a href="http://en.wikipedia.org/wiki/Alpha_Centauri_A">Alpha Centauri Aa>. 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 <span class="d2">an avatar, a representation of

                    a real person in a virtual worldspan>.p>

            <p>

                <span class="d3">The film was released in 2D and 3D formatsspan>, 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.p>

            <p>

                Read the rest of the <ahref="http://en.wikipedia.org/wiki/Avatar_(2009_film)">original

                    Wikipedia page about Avatara>p>

            <div class="mask">

            div>

        div>

    div>

div>

 

entity-results类中显示了Tab按钮,每个按钮控制左边文字的透明度,段落文字的高亮显示。

entity-source类中有三个段落span Calss分别为 d1 d2 d3,也就是高亮文字段落。

class=mask的空div放到最后,此Div也就是一个遮罩层。

四、CSS关键代码

.entity-source.entity-source span.show

{

    positionrelative;

}

.entity-source .mask

{

    displaynone;

    positionabsolute;

    top0;

    left0;

    height100%;

    width100%;

    z-index1;

}

.entity-source span

{

    z-index2;

}

.entity-source span.show

{

    background#ffc;

    color#000;

}

 

 

mask中的z-index:1 使得

mask 覆盖在左边文字内容之上。

z-nidex2又使得span段落覆盖在

mask > 之上。从而显示实现了段落文字高亮显示。

五、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://5thirtyone.com/archives/2206

Demo地址:http://5thirtyone.com/sandbox/samples/fadefocus/

Demo下载:http://5thirtyone.com/sandbox/samples/fadefocus/all.zip


==============================================================================
我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
实我是一个程序员

==============================================================================
Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计,皆可应用在项目、毕业设计、课程设计、期末/期/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值