作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试过这样的事情:
var Height = $(this).naturalHeight;
但是这不起作用。有没有办法做到这一点
格瑞兹
最佳答案
我在应用 jQuery 然后剥离 jQuery 后使用 native javascript 属性
.naturalWidth / .naturalHeight
在我使用的 jQuery 对象上
var width = this.naturalWidth;
var height = this.naturalHeight;
或
var width = $("selector").get(0).naturalWidth;
var height = $("selector").get(0).naturalHeight;
如果没有选择 jQuery 对象。
With get(0) on a jQuery object you can access the associated DOM-element 。在 native DOM 元素上,您可以使用 native javascript 代码(此处访问 native javascript 属性 .naturalWidth)
关于jquery - 有没有办法用jquery读出图像的 "naturalWidth"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1832907/
我是一名优秀的程序员,十分优秀!