1

好的,我有这个 jQuery 代码工作。移动鼠标时背景移动到正确的位置。现在我唯一想要的是在称为“船”的移动背景上轻松进出。这是代码。提前致谢。


var stageWidth = $('#Stage').width();
var stageHeight = $('#Stage').height();

// boat
var boatMinPosX = -100;
var boatMaxPosX = -900;
var boatMinPosY = -100;
var boatMaxPosY = -400;

// sunset
var sunsetMinPosX = -180;
var sunsetMaxPosX = 0;

sym.onMouseMove = function( pageX, pageY ){
// move boat
var boatRequestPosX = sym.getTranslation(0, stageWidth, boatMinPosX, boatMaxPosX, pageX);
var boatRequestPosY = sym.getTranslation(0, stageHeight, boatMinPosY, boatMaxPosY, pageY);
sym.$("boat").css({left:boatRequestPosX, top:boatRequestPosY});


// testing
var boatPosX = sym.$("boat").css("left");
console.log('boatPosX'+boatPosX);


}


// utility function
/*
@param      
* minInput          minimum Number of  input scale
* maxInput          maximum Number of  input scale
* minOutput         minimum Number of  output scale
* maxOutput         maximum Number of  output scale
* inputNumber       Number in input scale to be translated
*/
sym.getTranslation = function(minInput, maxInput, minOutput, maxOutput, inputNumber) {      
var translatedVal = ((inputNumber - minInput) * (maxOutput -minOutput)/(maxInput - minInput) ) +          minOutput;
return translatedVal;   
}
4

0 回答 0