Code for the effect of the next link on a javascript Image

Source: Internet
Author: User

Post Implementation Method:
Code
Copy codeThe Code is as follows:
<! 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>
<Title> No title page </title>
<Script src = "jquery-1.3.2.js" type = "text/javascript"> </script>
<Style type = "text/css">
. Rootclass {border: none; position: relative ;}
</Style>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ (". Rootclass"). mousemove (function (e ){
Var positionX = e. originalEvent. x | e. originalEvent. layerX | 0;
If (positionX <= $ (this). width ()/2 ){
This. style. cursor = 'url ("pre. cur"), auto ';
$ (This). attr ('title', 'click to view the previous file ');
$ (This). parent (). attr ('href ', $ (this). attr ('left '));
} Else {
This. style. cursor = 'url ("next. cur"), auto ';
$ (This). attr ('title', 'click to view the next one ');
$ (This). parent (). attr ('href ', $ (this). attr ('right '));
}
});
});
</Script>
</Head>
<Body>
<A href = "#">

</A>
</Body>
</Html>

Note: 1. Jquery needs to be called.
2. Here we use a speculative method to obtain the mouse position in the image and set the position of the image: relative
Use var positionX = e. originalEvent. x | e. originalEvent. layerX | 0; to obtain the value.
3. Add left = "http://www.google.cn" right = "http://www.baidu.cn" for the previous, next link address on the image for convenience. Remember to set <a href = "#"> </a>
DEMO code: http://demo.jb51.net/js/img_left_right/jquery_img_lr.htm

Packaging http://www.jb51.net/jiaoben/25129.html

Related Articles:
ClientX, pageX, offsetX, x, layerX, screenX, offsetLef
Differences between common functions of JS in IE and FireFox
Differences between javascript offsetX and layerX
JQuery click the image to jump to the previous or next function implementation code

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.