点击即可切换图片大小 [英] Toggle image size on click

查看:84
本文介绍了点击即可切换图片大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击图像时如何切换图像尺寸?这是我现在拥有的代码,当单击图像时,它会变大,但是会一直保持这种状态.如何使它从原始尺寸来回切换到600px?

How can I toggle an image size when the image is clicked? This is the code I have right now and when the image is clicked it becomes larger but it just stays that way. How can I make it toggle back and forth from the original size to the 600px?

$("img").click(function() {
$(this).css({height: "600px", width: "600px"});
});

推荐答案

$("img").click(function() {
   $(this).toggleClass("bigger");
});

在您的CSS中添加此

img .bigger {
    height: 600px;
    width: 600px;
}

这篇关于点击即可切换图片大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆