Web site want to make adaptive, PHP will automatically generate the different size of the summary thumbnail, but PHP has no way to get the user screen size, only by JS to get, JS get into PHP data is a string type, with (int) intval () can not be converted to an integer, can not do a numerical comparison, Solution ~ ~
1600) { //调用1600宽的图片} elseif ($sw_int > 1000) { //调用1000宽的图片} else { //调用800宽的图片}?>
Reply content:
Web site want to make adaptive, PHP will automatically generate the different size of the summary thumbnail, but PHP has no way to get the user screen size, only by JS to get, JS get into PHP data is a string type, with (int) intval () can not be converted to an integer, can not do a numerical comparison, Solution ~ ~
1600) { //调用1600宽的图片} elseif ($sw_int > 1000) { //调用1000宽的图片} else { //调用800宽的图片}?>
This is usually not the case, PHP generates different sizes of thumbnails to be static, and the thumbnail name should be regular, such as Image_0153431242_small.jpg, Image_0153431242_middle.jpg, Image_ 0153431242_big.jpg, image_0153431242_source.jpg this.
So the front-end JS as long as the adjustment is good, rather than pass to PHP processing, for example
This format does not easily handle browser-side caching, which affects the speed at which pages are opened two times.
In addition, you may not understand how PHP works. For PHP, JS is just a string that is processed and exported by PHP, that is, when the JavaScript code executes, the PHP process is already closed. PHP runs on the server side, JS runs on the browser side, and the two cannot interact at any time.
Own Baidu a bit srcset this label, Zhang Xin Xu has a few talk about this