gpt4 book ai didi

javascript - jquery,点击放大图片,然后点击agian让它回到之前的宽度

转载 作者:太空宇宙 更新时间:2023-11-04 14:33:18 26 4
gpt4 key购买 nike

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<img src="https://i0.wp.com/www.thekitchenwhisperer.net/wp-content/uploads/2014/04/BelgianWaffles8.jpg" width="100" class="image" />

<script>
$(document).ready(function() {
$('.image').click(function() {
$(this).css('width', '100%'); // original width is 500px
});
});
</script>

如何添加一些代码以便我再次单击它时,它会返回到之前的宽度 (100px)?

最佳答案

像这样?

 $(document).ready(function(){
$('.image').click(function(){
$(this).css('width', function(_ , cur){
return cur === '100px' ? '100%' : '100px'
});
});
});

Fiddle

关于javascript - jquery,点击放大图片,然后点击agian让它回到之前的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18969531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com