Home > Web Front-end > JS Tutorial > body text

JavaScript image automatic scaling and vertical centering processing function_image special effects

WBOY
Release: 2016-05-16 18:59:56
Original
1177 people have browsed it
复制代码 代码如下:



Untitled


















注释:
1、后面的testCss1和testCss2两个样式跟testCss是一样的。只是设置了大小。
2、红色部分的height和width必须定义,是设置存放img外面的父层容器的高和宽。
3、text-algin:为图片水平居中
4、display:block,必须设置。否则FF下启用自动缩放不起作用。

使用方法:
1、是需要在img的父层定义样式,包含上述注释里面提到的东西;
2、是img加上 


onload="autoSizeImg(this.parentNode,5,5,true)"

参数说明:
参数Contents一般采用this.parentNode,即使img的父容易
参数offsetWidth,offsetHeight分别是宽和高度居中的修正值。
参数vlmiddle设置为true则是垂直居中

[Ctrl A 全选 注:如需引入外部Js需刷新才能执行
]
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!