WordPress サイトの垂直リズムを整理するために、Web サイトに次の jQuery コードがあります。
$(window).bind('load', function(){
$(".wp-caption").each(function() {
/* variables */
var this_img = $(this);
var baseline = 24;
var img_height = this_img.outerHeight();
/* do the maths */
var remainder = parseFloat(img_height%baseline);
/* how much do we need to add? */
var offset = parseFloat(baseline-remainder);
var top_offset = Math.round(offset/2);
var bottom_offset = offset - top_offset;
/* apply the margin to the image */
this_img.css("margin-bottom",bottom_offset+"px");
this_img.css("margin-top",top_offset+"px");
});
});
これをもっと再利用できるようにしたいので、すべてのコードを に詰め込むのではなく.bind
、$(".wp-caption").verticalRhythm(24)
. これがプラグインが必要であることを意味するのかどうか、もしそうなら、それが正確に何を意味するのかはわかりません.
どんなアイデアや助けもいただければ幸いです