史上最牛X最简洁的Javascript图片缩放代码
源码:
function resize(img, width, height) {
(img.width > img.height)
? ((img.height = Math.min(height, width * img.height/img.width)) || (img.width = Math.min(width, img.width)))
: ((img.width = Math.min(width, height * img.width/img.height)) || (img.height = Math.min(height, img.height)));
}
稍微压缩一下:
function resize1(i,w,h){var a=i.width;var b=i.height;a>b?((i.height=Math.min(h,w*b/a))||(i.width=Math.min(w,a))):((i.width=Math.min(w,h*a/b))||(i.height = Math.min(h,b)));}
相关文档:
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
border border
border-bottom borderBottom
border-bottom-color borderBottomColor
border-bottom-style borderBottomStyle
border-bottom-width borderBottomWidth
border-color borderColor
border-left borderLeft ......
javascript内存泄露的问题一直以来都不受到大家的重视,原因是对用户的影响没有太实际的表现,或许近几年内存发展迅速。脚本内存再泄露也不会有太大影响。
当然作为前端开发的同学们,就不能有这样的侥幸心理。出现memory leaks很大程度上是因为程序的不成熟和编码不太规范造成的。不过,这里就不说如何出现问题的,对问题 ......
CDATA 内部的所有东西都会被解析器忽略。
假如文本中包含了大量的 "<" 和 "&" 字符 - 就像编程代码中经常出现的情况一样 - 那么这个 XML 元素就可以被定义为一个 CDATA 部分。
CDATA 区段开始于 "<![CDATA[",结束于 "]]>":
<script type="text/javascri ......
javascript中innerHtml用法
2009-04-21 22:52
<html>
<head>
<script language="javascript">
function Test(){
var str="";
str+="Hello,";
str+="This ......