Jquery method for implementing the spotlight Effect

Source: Internet
Author: User

Jquery method for implementing the spotlight Effect

This article mainly introduces jquery's method to achieve the spotlight effect, which can display the highlight of the current image when the mouse slides over the image, and the spotlight effect when other images are dimmed, which is of great practical value, for more information, see

 

 

This article describes how jquery achieves the spotlight effect. Share it with you for your reference. The specific analysis is as follows:

Sometimes a website needs to use jquery to implement an image spotlight effect. When the mouse slides over a single icon in a group, the current highlight is displayed, and other icons become dimmed. First, let the mouse touch the current image, make all other images transparent, and then display the current prompt. When the mouse is removed, the current prompt is hidden, make the transparency of all background colors normal. Here we will introduce how to use jquery to implement the spotlight effect.

Jquery implements the spotlight as follows:

Jquery code

The Code is as follows:

<! DOCTYPE>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> jquery spotlight plug-in making jquery image effects move the mouse over the current Image Highlight </title>
<Meta name = "description" content = "jquery spotlight plug-in makes jquery image effects. When the mouse slides over the image, the current image is highlighted and the remaining images are dimmed. "/>
</Head>
<Body>
<Style type = "text/css">
* {Margin: 0; padding: 0; list-style-type: none ;}
A, img {border: 0 ;}
Img {vertical-align: middle}
/* Lamp */
. Lamp {height: pixel PX; width: 960px; position: relative; margin: 0 auto ;}
. Lamp. sublight {position: absolute; display: block; overflow: hidden ;}
. Lamp. pic1 {top: 0; left: 0; width: 240px; height: pixel PX ;}
. Lamp. pic2 {top: 0; left: 240px; width: 480px; height: 183px ;}
. Lamp. pic3 {top: 0; left: 720px; width: 240px; height: 183px ;}
. Lamp. pic4 {top: 183px; left: 240px; width: 240px; height: 183px ;}
. Lamp. pic5 {top: 183px; left: 480px; width: 240px; height: 183px ;}
. Lamp. pic6 {top: 183px; left: 720px; width: 240px; height: 183px ;}
</Style>
<Div class = "lamp">
<A target = "_ blank" href = "http://www.jb51.net/" class = "sublight pic1"> </a>
<A target = "_ blank" href = "http://www.jb51.net/" class = "sublight pic2"> </a>
<A target = "_ blank" href = "http://www.jb51.net/" class = "sublight pic3"> </a>
<A target = "_ blank" href = "http://www.jb51.net/" class = "sublight pic4"> </a>
<A target = "_ blank" href = "http://www.jb51.net/" class = "sublight pic5"> </a>
<A target = "_ blank" href = "http://www.jb51.net/" class = "sublight pic6"> </a>
</Div>
<Script type = "text/javascript" src = "jquery. Js "> </script>
<Script type = "text/javascript">
// Highlight
Var blockHighLight = (function (window, $, undefined ){
Var markers = [];
Return function (boxCls, itemCls, sizeArr ){
Var box = $ (boxCls );
ItemCls = itemCls | "";
Box. find (itemCls). each (function (I ){
Var self = $ (this );
Var arr, w, h, marker;
If (sizeArr! = Undefined ){
Arr = sizeArr [I]. split (",");
W = arr [0];
H = arr [1];
} Else {
W = self. find ("img"). attr ("width ");
H = self. find ("img"). attr ("height ");
}
Marker = $ ('<div style = "cursor: pointer; top: 0; left: 0; position: absolute; width:' + w + 'px; height: '+ h +' px; filter: alpha (opacity = 0); opacity: 0; background-color: #000; "> </div> ');
Self. append (marker );
Self. mouseover (function (){
For (var I = 0; I <markers. length; I ++ ){
Markerspolici2.16.show().css ({"opacity": '0. 2', "filter": "alpha (opacity = 20 )"});
}
Marker. hide ();
});
Markers. push (marker );
});
Box. mouseout (function (){
For (var I = 0; I <markers. length; I ++ ){
Markerspolici2.16.css ({"opacity": '0', "filter": "alpha (opacity = 0 )"});
}
})
}
}) (This, $ );
BlockHighLight (
". Lamp", // parent Element
". Sublight", // sub-element set
[
'000000', // the width and height of the first image
'000000', // the width and height of the second image
'000000', // width and height of the third image
'000000', // width and height of the fourth Image
'000000', // width and height of the fifth Image
'000000' // width and height of the sixth Image
]
);
</Script>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.