Window innerWidth 和 innerHeight 属性(不包含工具条和滚动条)
innerheight 返回窗口的文档显示区的高度。
innerwidth 返回窗口的文档显示区的宽度。
使用 outerWidth 和 outerHeight 属性获取加上工具条与滚动条窗口的宽度与高度。
element.offsetHeight
返回任何一个元素的高度包括边框和填充,但不包括边距
element.poffsetWidth
返回元素的快递,包括边框和填充,但不包括边距
element.offsetTop
返回当前元素的相对垂直偏移位置的偏移容器(相对于doc来说的)
element.offsetLeft
返回当前元素的相对水平偏移位置的偏移容器(相对于doc来说的)
图片上传问题的解决方式,如果是图片在本地的话,而不是别的服务器那边的就可以用js下载
var alink = document.createElement(“a”);
alink.href = img;
alink.download = img;
alink.click();
如果资源在别的服务器那边的话,只能用后台代码写,如下
js :
window.location.href = “/api/product/download?filePath=”+ img +"&id="+itemId
java后台代码:
/**
* 文件下載的處理
* @param request
* @param response
* @throws IOException
*/
public static void downLoadFile(HttpServletRequest request, HttpServletResponse response) throws IOException{
String filePath = request.getParameter("filePath");
int suffixIndex = filePath.lastIndexOf("/");
// String fileName = filePath.substring(suffixIndex + 1,filePath.length());
String fileName = request.getParameter("id");
//读取字符编码
String encoding = "UTF-8";
//设置响应
response.setCharacterEncoding(encoding);
response.setContentType("text/html; charset=" + encoding);
response.setHeader("Pragma","public");
response.setHeader("Cache-Control","max-age=30");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".png");
//作出响应
URL url = new URL(filePath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
InputStream inStream = conn.getInputStream();
byte[] buf = new byte[1024 * 10];
OutputStream os = response.getOutputStream();
int len = 0;
if(conn.getResponseCode() == 200) {
while ((len = inStream.read(buf)) != -1) {
os.write(buf,0,len);
os.flush();
}
closeStream(inStream,os);
}
}
/**
* 关闭流字节流的操作
* @param in
* @param out
*/
public static void closeStream(InputStream in,OutputStream out){
try {
if(in != null){
in.close();
}
if(out != null){
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}