当前位置:网站首页>Size limit display of pictures
Size limit display of pictures
2022-07-27 09:03:00 【IChocolateKapa】
<span style="font-size:24px;">function setImgWidthHeight(imgJqObj){
imgJqObj.each(function() {
var $thisImg = $(this);
console.log($thisImg.height());
console.log($thisImg.width());
var maxWidth = 500; // The maximum width of the picture
var maxHeight = 500; // Maximum height of picture
$("<img/>").attr("src", $thisImg.attr("src")).load(function() {
var realWidth = this.width;
var realHeight = this.height;
if(realWidth >= maxWidth){
$thisImg.attr("width", maxWidth);
// $thisImg.attr("height", maxHeight);
}
if(realHeight >= maxHeight){
// $thisImg.attr("width", maxWidth);
$thisImg.attr("height", maxHeight);
}
})
})
}</span>stay html On the page ,<img> If there is no setting in the label width and height attribute , You can't get
<$thisImg.height() and $thisImg.width(),[ The result is 0], If it is set, you will get the set value .Set the height and width according to the actual size of the picture , Excessive display of the maximum set value , If it is too small, it will be displayed according to its own value , So get the true width and height of the picture :
$("<img/>").attr("src", $thisImg.attr("src")).load(function() {
var realWidth = this.width;
var realHeight = this.height;
}) // Must use load Method 边栏推荐
- 网络IO总结文
- 1.3.1 Full Permutation Problem
- 【微服务~Sentinel】Sentinel之dashboard控制面板
- NIO this.selector.select()
- Matlab drawing skills and examples: stackedplot
- Explain cache consistency and memory barrier
- 音乐体验天花板!14个网易云音乐的情感化设计细节
- 4279. Cartesian tree
- Horse walking oblique sun (backtracking method)
- 2036: [Blue Bridge Cup 2022 preliminary] statistical submatrix (two-dimensional prefix sum, one-dimensional prefix sum)
猜你喜欢

NIO this.selector.select()

async/await的执行顺序以及宏任务和微任务

Unity3d 2021 software installation package download and installation tutorial

CUDA programming-01: build CUDA Programming Environment
![[interprocess communication IPC] - semaphore learning](/img/47/b76c329e748726097219abce28fce8.png)
[interprocess communication IPC] - semaphore learning

Mmrotate trains its dataset from scratch

08_ Service fusing hystrix

PVT的spatial reduction attention(SRA)

4274. Suffix expression

4279. Cartesian tree
随机推荐
Linear list (sequential storage, chain storage) (linked list of leading nodes, linked list of non leading nodes)
Activation functions commonly used in deep learning
flex:1的原理
易语言编程: 让读屏软件可获取标签控件的文本
“鼓浪屿元宇宙”,能否成为中国文旅产业的“升级样本”
【微服务~Sentinel】Sentinel之dashboard控制面板
qt中使用sqlite同时打开多个数据库文件
CUDA programming-01: build CUDA Programming Environment
[flutter -- geTx] preparation
Solve the problem of Chinese garbled code on the jupyter console
苹果降价600元,对本就溃败的国产旗舰手机几乎是毁灭性打击
QDoubleValidator不生效问题解决办法
[daily algorithm day 96] Tencent interview question: merge two ordered arrays
NiO Summary - read and understand the whole NiO process
3311. Longest arithmetic
基于restful页面数据交互
Arm undefined instruction exception assembly
Unity3D 2021软件安装包下载及安装教程
拍卖行做VC,第一次出手就投了个Web3
新年小目标!代码更规范!