keydown和toggle变量的值增加1并切换为0

时间:2017-03-23 09:19:18

标签: javascript jquery css

设置我将在我的项目中使用的元素

  function bossShanLi() {
  const shanLi = 'Shan-Li',
  user = '史豔文';
  var click = false;
  var userBlood=100;
  var attack = document.getElementById('attack'),
   defense = document.getElementById('defense'),
   items = document.getElementById('item'),
   magic = document.getElementById('magic'),
   overPower = document.getElementById('over-power');
   yushan = document.querySelector('#yushan');

这个功能是像css的rotate3d一样旋转3d,我设置了var x y z并且我设置了特定的按键,按下x将变为1,y和z但是它不起作用

   function rotate3d(e){
    var x = 0;
    var y = 0; 
    var z = 0;
    document.onkeydown = function(){
    if(e.keyCode === 65){
        x = 1;
        console.log(e.keyCode);
    }
    if(e.keyCode === 83){
        y = 1;
    }
    if(e.keyCode === 68){
        z = 1;
    }
}
          var degree = e.clientX||e.clientY;
          yushan.style.transform='rotate3d('+ x +','+ y +','+ z 
         +','+degree+'deg)';

下面这就像控制台日志一样,我把它作为一个span和innerHTML来查看值和什么; s继续

   let number = document.querySelector('.number');
    number.innerHTML='degree'+':'+e.clientX+','+e.clientY+','+degree+ 
    'x'+':'+x+'</br>'+'y'+':'+y+'</br>'+'z'+':'+z;
    }

     window.addEventListener('mousemove',rotate3d);
   }
   window.onload=bossShanLi;

0 个答案:

没有答案