我有一个出现多次的图像,但我需要每次出现时图像宽度增加 50px。
我尝试使用 jQuery 来完成此任务,但目前运气不佳,有什么想法我哪里出错了吗?
循环获取每一位内容的 HTML 是:
<div class="hideme">
<h3 class="text-white"><?php the_sub_field('whatcanwedo_stats_number'); ?></h3>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/tash5.png" alt="tash5" class="what-can-we-do-tash" />
<p><?php the_sub_field('whatcanwedo_stats_content'); ?></p>
</div>
我拥有的 jQuery 是:
var w = 50;
var newWidth;
// what can we do tash
$('.what-can-we-do-tash').each(function(){
newWidth === w;
$(this).attr('width',newWidth);
w+50;
});
但是这似乎没有做任何事情:(
最佳答案
您应该使用.css()
:
$('.what-can-we-do-tash').css('width', function(i){
return $(this).width() + (i * 50);
});
这里正在工作:http://jsfiddle.net/wDpvV/1/
关于jquery - 将图像宽度增加 50px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16647856/