how can processing.js detect browser's size?

雨燕双飞 提交于 2019-12-04 11:00:18

问题


As mentioned, how can processing.js respond to a browser's size? (responsive design) i've tried screen.width and screen.height but it didn't work well. It seems only detect the size of the computer's screen size.

What's more, i want to keep pace with the window's size when dragged and changed the size of the browser


回答1:


 size(window.innerWidth, window.innerHeight); 

according to https://groups.google.com/forum/?fromgroups=#!topic/processingjs/2-U_P7_BHlY

or

void setup() {
size( $(window).width(),
    $(window).height() );
...
}

according to Get Viewport Width With JQuery and Use In Processing JS




回答2:


Here is how I approached this issue using Zerb Foundation 3 responsive web framework, Javascript, jQuery and Processing.js. You can take a look at Living Map Project if you want to dig through the source.

in javascript / jquery:

// handle page resizing
$(window).resize(function() {
var pjs = Processing.getInstanceById('livingmap');
pjs.resizeSketch(document.getElementById('div_p5canvas').offsetWidth,  document.getElementById('div_p5canvas').offsetHeight);
} );

in your .pde processing js code (note: the calculation was what I felt worked well using zurb's foundation 3, the grid I defined and how that translated as pixels:

void resizeSketch(int w, int h) {
  if (w < 680) {
    size(w, floor(float(w)/680*610) - 30);
    } else size(680, 610 - 30);
}

in your html:

<div class="flex-video widescreen" id="div_p5canvas"
<canvas id="livingmap" data-processing-sources="livingmap_2.pde" style="height:auto; width:auto; focus { outline: 0; }" tabindex="1"></canvas>
</div>


来源:https://stackoverflow.com/questions/12331094/how-can-processing-js-detect-browsers-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!