Good afternoon, I have a mousemove effect and would like some help:
I'm passing some parameters fixed, and I would put them dynamic.
I need to make a picture that is for each step the mouse, that when searching for the image (sprite) database, according to the parameters already know how to divide the spaces where content will appear the images.
The following code:
- jQuery.noConflict();
- function moveImages(IDLoader, numImages) {
- jQuery(document).ready(function ($) {
- var cursorObject = {
- offsetLeft: 0,
- offsetTop: 0,
- cursorX: 0,
- run: function (obj) {
- if(obj.length > 0) {
- obj.live("mouseover mousemove mouseout", function (event) {
- var pos = $(this).position();
- cursorObject.offsetLeft = pos.left;
- cursorObject.offsetTop = pos.top;
- switch(event.type) {
- case "mouseover":
- cursorObject.mouseOver(obj, event);
- break;
- case "mousemove":
- cursorObject.mouseMove(obj, event);
- break;
- case "mouseout":
- cursorObject.mouseOut(obj);
- break
- }
- })
- }
- },
- mouseOver: function (event) {
- cursorObject.updatePosition(event)
- },
- mouseMove: function (obj, event) {
- var qtdImg = numImages;
- var totalDiv = 180;
- var tamImgSprite = qtdImg * totalDiv;
- var tmEspaco = totalDiv / qtdImg;
- cursorObject.updatePosition(event);
- var img = $("id", obj);
- var j = $(obj).attr("id");
- var http = "../img2/image1.jpg";
- var array = [];
- for(var i = 0; i < qtdImg; i++) {}
- if(cursorObject.cursorX <= 225) {
- $("#" + IDLoader + " img").replaceWith("<img style='background: url(" + http + ");width: " + 180 + "px;height: " + 249 + "px;display: block;background-position: " + 0 + "px " + 0 + "px;margin: " + 0 + "px;padding: " + 0 + "px;vertical-align: middle'>")
- }
- if(cursorObject.cursorX > 225 && cursorObject.cursorX <= 270) {
- $("#" + IDLoader + " img").replaceWith("<img style='background: url(" + http + ");width: " + 180 + "px;height: " + 249 + "px;display: block;background-position: " + -150 + "px " + 0 + "px;margin: " + 0 + "px;padding: " + 0 + "px;vertical-align: middle'>")
- }
- if(cursorObject.cursorX > 270 && cursorObject.cursorX <= 315) {
- $("#" + IDLoader + " img").replaceWith("<img style='background: url(" + http + ");width: " + 180 + "px;height: " + 249 + "px;display: block;background-position: " + -300 + "px " + 0 + "px;margin: " + 0 + "px;padding: " + 0 + "px;vertical-align: middle'>")
- }
- if(cursorObject.cursorX > 315 && cursorObject.cursorX <= 360) {
- $("#" + IDLoader + " img").replaceWith("<img style='background: url(" + http + ");width: " + 180 + "px;height: " + 249 + "px;display: block;background-position: " + -475 + "px " + 0 + "px;margin: " + 0 + "px;padding: " + 0 + "px;vertical-align: middle'>")
- }
- },
- mouseOut: function () {
- $("#" + IDLoader + " img").replaceWith("<img style='background: url(" + http + ") ;width: " + 0 + "px;height: " + 0 + "px;display: block;background-position: " + 0 + "px " + 0 + "px'>")
- },
- updatePosition: function (event) {
- cursorObject.cursorX = Math.round(event.pageX - cursorObject.offsetLeft)
- }
- };
- $(function () {
- cursorObject.run($("#" + IDLoader))
- })
- })
- };
[moderator reformatted]