JQuery implements the next switching function on the Image

Source: Internet
Author: User

When you move the mouse over an image on Renren's album and cool dog music website, the shape of the mouse changes according to its position on the image.

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.bkjia.com right = http://www.liehuo.org for the previous, next link address on the image for convenience. Remember to set <a href = "#"> </a>

Reference: 1. jQuery obtains the relative coordinates of the current mouse and click the image to jump to the previous or next page.

2. Differences between offsetX and layerX

3. Summary of differences between IE and FireFox in JS

4. clientX, pageX, offsetX, x, layerX, screenX, offsetLeft

Implementation Code:

<! 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> the previous image demonstrates Liehuo. Net </title> <script src =" http://www.bkjia.com /Uploads/common/jquery-1.3.2.min.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 one (the fire homepage is opened by default) '); $ (this ). parent (). attr ('href ', $ (this ). attr ('left');} else {this. style. cursor = 'url ("next. cur "), auto'; $ (this ). attr ('title', 'click to view the next one (open fire navigation by default) '); $ (this ). parent (). attr ('href ', $ (this ). attr ('right') ;}}) ;}); </script> 

Tip: the code can be modified before running!

Source: http://dooom.cnblogs.com

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.