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