使用Javascript自动调整交换图像 //下面的行获取标记类型,在本例中,它是图像标记

使用Javascript自动调整交换图像 //下面的行获取标记类型,在本例中,它是图像标记,javascript,dom,Javascript,Dom,我正在寻找自动调整,然后在页面加载后自动复制新图像。猫填满了图像,但它压扁了图像。我假设我将使用Javascript 图片链接是猫。为什么猫被压扁了:(.我的意思是猫图片压扁了,而不是实际的猫XD.Lol,我在你的帖子里看不到猫;)。你怎么知道猫在图像上的位置,这样你就可以裁剪它?一种简单的跨浏览器方式是将图像包装到一个大小为divs的集合overflow:hidden,然后将图像定位到divs中的正确位置。 //The line below gets the tag type, in this

我正在寻找自动调整,然后在页面加载后自动复制新图像。猫填满了图像,但它压扁了图像。我假设我将使用Javascript

图片链接是猫。为什么猫被压扁了:(.我的意思是猫图片压扁了,而不是实际的猫XD.Lol,我在你的帖子里看不到猫;)。你怎么知道猫在图像上的位置,这样你就可以裁剪它?一种简单的跨浏览器方式是将图像包装到一个大小为
div
s的集合
overflow:hidden
,然后将图像定位到
div
s中的正确位置。
//The line below gets the tag type, in this instance, it's the image tag <img>
var imgs = document.getElementsByTagName("img");
//This is where the magic happens. We start by setting up the concept
for (var i = 0, l = imgs.length; i < l; i++) {
//This is where we replace imgs (the variable that gets the image tag), gets the requirements with     "[i]", and replaces the images met by the requirements with the src (source link)
imgs[i].src = "http://3.bp.blogspot.com/-KL7d7LdSANg/Tm5VLQf9k4I/AAAAAAAAACo/cSV52JoD7vk/s1600/cat-wallpaper-34-713472.jpg";
}