在MouseMove上轻松输出

时间:2014-08-27 09:25:33

标签: jquery background jquery-animate mouse onmousemove

好的,我有这个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;   
}

0 个答案:

没有答案