Even though the question isn't very clear, I think the problem is that you are trying to look for a keycode, while if you try and add:
function anim(e) {
console.log(e.keyCode);
}
you'll get undefiend, and that's your problem (click event does not return an e.keyCode value)
so you can actually add to the condition:
function anim(e) {
if (e.keyCode == 37 || e.keyCode === 'undefined') {
telesoVlevo -= 2;
teleso.style.left = telesoVlevo + "px";
if (telesoVlevo <= 0) {
telesoVlevo += 2;
}
}
}
of course that's assuming the CSS positioning is properly set: a wrapper that is set to position: realative and the element you're trying to animate, with position: absolute.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…