【问题标题】:How would I view console log of this code?我将如何查看此代码的控制台日志?
【发布时间】:2015-01-22 13:42:08
【问题描述】:

我正在尝试解决先前堆栈溢出中所述的问题,但我没有收到任何回复,所以无论如何我都在尝试自己解决...

我将如何查看此代码中的控制台数据,以便准确了解正在计算的高度?

window.onscroll = function (event) {
   var offset = window.pageYOffset;
   var wheight = window.innerHeight;
   var html = document.documentElement;
   var docheight = Math.max(document.body.scrollHeight, document.body.offsetHeight,
   html.clientHeight, html.scrollHeight, html.offsetHeight);
   var progress = offset / wheight;

   document.getElementById("SVGID_1_").setAttribute("y1", 93000 + progress * 93000);
}

jsfiddle 在这里:http://jsfiddle.net/11x3cwnr/

【问题讨论】:

  • 控制台没有记录任何内容?

标签: javascript jquery testing console.log


【解决方案1】:

键入console.info(some_variable) 并在浏览器的控制台中查看。通常输入 F12

【讨论】:

    【解决方案2】:

    只需将 console.log 行添加到您的 javascript 中,如下所示: http://jsfiddle.net/11x3cwnr/4/

    按 F12 查看控制台输出(在大多数浏览器中)。

    【讨论】:

      【解决方案3】:

      使用 console.log 语句更新代码,如下所示:

      window.onscroll = function (event) {
         var offset = window.pageYOffset;
         var wheight = window.innerHeight;
         var html = document.documentElement;
         var docheight = Math.max(document.body.scrollHeight, document.body.offsetHeight,
         html.clientHeight, html.scrollHeight, html.offsetHeight);
         var progress = offset / wheight;
         // HERE'S THE LOG STATEMENT
         console.log("Progress = " + progress);
         document.getElementById("SVGID_1_").setAttribute("y1", 93000 + progress * 93000);
      }
      

      然后使用 Chrome 或 Firefox 并右键单击示例中的面部图像,检查元素,然后选择控制台选项卡。或者,至少在 Chrome 中,只需按 F12 即可直接进入控制台。现在当你滚动人脸图像时,你会看到进步的价值是什么。

      【讨论】:

        猜你喜欢
        • 2014-08-03
        • 2020-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多