将jquery函数转换为js

时间:2015-02-27 22:30:16

标签: javascript jquery

有人可以帮我将以下代码转换为普通的js

  $(function() {
      var wheight = $(window).height(); //get height of the window
      $('.fullheight').css('height', wheight);

      $(window).resize(function() {
          var wheight = $(window).height();
          $('.fullheight').css('height', wheight);
      });
  });

1 个答案:

答案 0 :(得分:2)

document.addEventListener( "DOMContentLoaded", func, false )
window.addEventListener( "resize", func, false);

function func() {
    var wheight = window.outerHeight;
    var elems   = document.querySelectorAll('.fullheight');

    for (var i=elems.length; i--;) {
        elems[i].style.height = wheight + 'px';
    }
}