功能不起作用

时间:2017-06-25 20:18:51

标签: javascript jquery html css pacman

我正在尝试为每个div收集它的边框颜色(以检查仅适用于这些类型的div的后续函数)。但是,当我在console.log()每个div的边框颜色时,它一直说边框颜色是未定义的,即使我用css中的边框颜色定义它们。任何人都知道可能会发生什么?

此外,当我尝试将位置顶部和左侧作为div时,如果我按以下方式构造它,它会使我无效:$('name')。position()。left - >说position()。left是无效的....

这是我的代码:

function collision() {
  $( ".game-window" ).each( function () {
    //  var wall = $(this).find(".game-window").css("border-color", "blue");

    var walls = document.getElementsByTagName("div");
    walls = $(this);

    for(var i = 0; i < walls.length; i++){                
      var name = walls[i].getAttribute('id');
      var border = $('name').css('border-color');
      console.log(border);
      var position = $('name').position();

      if (border == 'solid blue') {
        wallPositions = {  
                          'left': position().left, 
                          'right': position().left + 
                           $('name').width(),
                          'top': position().top,
                          'bottom': position().top + pacman.height()
        };

        pacManPositions = { 
                             'left': parseInt(pacman.css('left')),
                             'right': parseInt(pacman.css('left')) + pacman.width(),
                             'top': parseInt(pacman.css('top')),
                             'bottom': parseInt(pacman.css('top')) + pacman.height()
        };

        console.log(wallPositions);
        console.log("what");

        if ( (pacManPositions.left <wallPositions.left && 
              pacManPositions.right > wallPositions.left) ||
             (pacManPositions.left < wallPositions.right && 
             pacManPositions.right > wallPositions.right) ||
             (pacManPositions.left < wallPositions.right && 
             pacManPositions.right > wallPositions.left) ) {
              console.log("what");

            if ( (pacManPositions.top >  wallPositions.top &&  
                 pacManPositions.top <  wallPositions.bottom) ||
                 ( pacManPositions.top < wallPositions.top &&  
                 pacManPositions.top >  wallPositions.bottom) ||
                 ( pacManPositions.top >  wallPositions.top && 
                 pacManPositions.bottom <  wallPositions.bottom) ) {

              console.log("oh no");
            }
              consolelog("its fine");
         }


       }
     }

   });

0 个答案:

没有答案