自动等比例缩放网页中的图片
resizeimg.js
- window.onload = function() {
- for (var index = 0; index < document.images.length; index++) {
- var widthRestriction = 400;
- var heightRestriction = 400;
- var rate = document.images[index].width / document.images[index].height;
- if (document.images[index].width > widthRestriction) {
- document.images[index].width = widthRestriction;
- document.images[index].height = widthRestriction / rate;
- } else if (document.images[index].height > heightRestriction) {
- document.images[index].height = heightRestriction;
- document.images[index].width = heightRestriction * rate;
- }
- document.images[index].onclick = function() {window.open(this.src)};
- document.images[index].title = document.images[index].title + ' 点击在新窗口中查看原图';
- }
- }
相关日志
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
还没有评论。
发表评论