提问者:小点点

将简单的jQuery代码转换为普通的js


我已经将所有jQuery脚本转换为纯javascript代码

我只剩下一个了,是他让我筋疲力尽

它是关于一个用jQuery编写的响应性Facebook页面插件

需要你的帮助。 谢啦!

`jQuery(document).ready(function ($) {
  $(window).bind("load resize", function () {
    setTimeout(function () {
      var container_width = $('#fb-container').width();
      $('#fb-container').html('<div class="fb-page" ' +
        'data-href="https://www.facebook.com/cloverepublic/"' +
        ' data-width="' + container_width + '" data-tabs="timeline" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="false"><div class="fb-xfbml-parse-ignore"><blockquote cite="http://www.facebook.com/IniciativaAutoMat"><a href="https://www.facebook.com/cloverepublic/">Clove Republic</a></blockquote></div></div>');
      FB.XFBML.parse();
    }, 50);
  });
});`

共1个答案

匿名用户

我试过了,但没用

var ready = (callback) => {
  if (document.readyState != "loading") callback();
  else document.addEventListener("DOMContentLoaded", callback);
}

ready(() => { 
  window.addEventListener('load',responsivefb);
  window.addEventListener('resize',responsivefb);
});

let fbcontainer = document.querySelector('#fb-container');

function responsivefb() {
  setTimeout(()=> {
    let container_width = parseFloat(getComputedStyle(fbcontainer, null).width.replace("px", ""))
    fbcontainer.innerHTML('<div class="fb-page" ' +
      'data-href="https://www.facebook.com/cloverepublic/"' +
      ' data-width="' + container_width + '" data-tabs="timeline" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="false"><div class="fb-xfbml-parse-ignore"><blockquote cite="http://www.facebook.com/IniciativaAutoMat"><a href="https://www.facebook.com/cloverepublic/">Clove Republic</a></blockquote></div></div>');
    FB.XFBML.parse();
  }, 50);
};