Javascript 如何使用鼠标盖停止图像旋转?

Javascript 如何使用鼠标盖停止图像旋转?,javascript,html,Javascript,Html,我已经创建了一个旋转图像的函数,现在我想做的是在使用mouseover命令时停止图像旋转。这是js编码,我必须让图像旋转 var m = { Z : 100, xm : 0, xmm : .25, ymm : 0, ym : 0, mx : 0, nx : 0, ny : 0, nw : 0, nh : 0, xR : 0, nI : 0, scr : 0, img : 0, run : function () { m.xm += (m.xmm - m.xm) *

我已经创建了一个旋转图像的函数,现在我想做的是在使用mouseover命令时停止图像旋转。这是js编码,我必须让图像旋转

var m = {
Z   : 100,
xm  : 0,
xmm : .25,
ymm : 0,
ym  : 0,
mx  : 0,
nx  : 0,
ny  : 0,
nw  : 0,
nh  : 0,
xR  : 0,
nI  : 0,
scr : 0,
img : 0,

run : function () {
    m.xm += (m.xmm - m.xm) * .1;
    if (m.ym < m.nw * .15) m.ym++;
    m.xR += m.xm;
    for (var i = 0; i < m.nI; i++){
        var A = (i * 360 / m.nI) + m.xR;
        var x = Math.cos(A * (Math.PI / 180));
        var y = Math.sin(A * (Math.PI / 180));
        var a = m.img[i];
        a.style.width  = ''.concat(Math.round(Math.abs(y * m.ym) + y * m.Z), 'px');
        a.style.left   = ''.concat(Math.round((m.nw * .5) + x * ((m.nw * .5) - (m.nw * .05)) - ((Math.abs(y * m.ym) + y * m.Z) * .5)), 'px');
        a.style.height = ''.concat(Math.round(m.ym + y * m.Z), 'px');
        a.style.top    = ''.concat(Math.round((m.nh * .5) - (m.ym * .5) - x * (m.Z * .5) - (m.ymm * y)), 'px');
        a.style.zIndex = 600 + Math.round(y);
        m.setOpacity(a, (y * 50) + 100);
    }
    setTimeout(m.run, 30);
},
var m={
Z:100,
xm:0,
xmm:.25,
ymm:0,
ym:0,
mx:0,
nx:0,
纽约:0,,
西北:0,,
新罕布什尔州:0,
xR:0,
倪:0,,
scr:0,
img:0,
运行:函数(){
m、 xm+=(m.xmm-m.xm)*.1;
if(m.ym
我确实没有详细阅读您的代码,但您可能要做的是在函数外部设置一个参数,或者为旋转图像的函数设置一个全局参数,将其称为“rotate”,并将其设置为TRUE

然后,在进行实际旋转之前,检查此“旋转”参数是否设置为TRUE,如果设置为TRUE,则旋转

现在,在MouseOver上,您所要做的就是将“rotate”参数设置为FALSE,然后当setTimeout触发器过期且函数再次启动时,如果设置为FALSE,imagee将不会旋转,因为它没有通过测试

另一种方法是将setTimeout设置为仅在不在mousenotover上时触发,因此如果在mousenotover上,则不要设置超时,否则,设置超时

这只是我刚刚想到的两个想法阅读你的代码,我想你可以考虑一下,然后决定这些解决方案是否是你喜欢的,如果不是,那么我很想知道你决定了什么


干杯。

我真的没有详细阅读您的代码,但您可能要做的是在函数外部设置一个参数,或者为旋转图像的函数设置一个全局参数,称之为“旋转”,然后将其设置为TRUE

然后,在进行实际旋转之前,检查此“旋转”参数是否设置为TRUE,如果设置为TRUE,则旋转

现在,在MouseOver上,您所要做的就是将“rotate”参数设置为FALSE,然后当setTimeout触发器过期且函数再次启动时,如果设置为FALSE,imagee将不会旋转,因为它没有通过测试

另一种方法是将setTimeout设置为仅在不在mousenotover上时触发,因此如果在mousenotover上,则不要设置超时,否则,设置超时

这只是我刚刚想到的两个想法阅读你的代码,我想你可以考虑一下,然后决定这些解决方案是否是你喜欢的,如果不是,那么我很想知道你决定了什么


干杯。

下一个代码只是一个近似值,更像是一个“伪代码”,而不是一个生产代码。无论如何,您可以根据需要随意修改

var m = {
run: function() {
    this.isRunning = true;
    // when complete the cycle
    this.cycle = true;
},
play: function() {
    this.timeout = setTimeout((function($this){
        if($this.animCheck !== undefined) clearInterval($this.animCheck);
        $this.run();
    })(this), this.frames);
},
pause: function() {
    this.animCheck = setInterval((function($this) {
        // Obviously, you've to pause the animation when the cycle is finished.
        if($this.cycle) clearTimeout($this.timeout);
    })(this), this.frames);
    return !!this.animCheck;
},
init: function() {
    this.frames = 30;
    this.isRunning = true;
    [the element].addEventListener('mouseover', function() {
        if(this.pause()) this.isRunning = false;
    })
    this.play();
}
})


m、 init()

下一个代码只是一个近似值,更像是一个“伪代码”,而不是生产代码。无论如何,您可以根据需要自由修改

var m = {
run: function() {
    this.isRunning = true;
    // when complete the cycle
    this.cycle = true;
},
play: function() {
    this.timeout = setTimeout((function($this){
        if($this.animCheck !== undefined) clearInterval($this.animCheck);
        $this.run();
    })(this), this.frames);
},
pause: function() {
    this.animCheck = setInterval((function($this) {
        // Obviously, you've to pause the animation when the cycle is finished.
        if($this.cycle) clearTimeout($this.timeout);
    })(this), this.frames);
    return !!this.animCheck;
},
init: function() {
    this.frames = 30;
    this.isRunning = true;
    [the element].addEventListener('mouseover', function() {
        if(this.pause()) this.isRunning = false;
    })
    this.play();
}
})


m、 init()

如何将onmouseover设置为false?如何将onmouseover设置为false?谢谢您的帮助。事实上,我只是想弄明白。谢谢你的帮助。事实上我只是想弄明白。