【发布时间】:2016-08-20 10:08:09
【问题描述】:
您好,我想简化这 4 个类似的功能。只有选择器最终发生了变化。请问我该怎么做?非常感谢!
$('.box.standard .title').css({
'position' : 'absolute',
'left' : '50%',
'top' : '50%',
'margin-left' : -$('.box.standard .title').outerWidth()/2,
'margin-top' : -$('.box.standard .title').outerHeight()/2
});
$('.box.large .title').css({
'position' : 'absolute',
'left' : '50%',
'top' : '50%',
'margin-left' : -$('.box.large .title').outerWidth()/2,
'margin-top' : -$('.box.large .title').outerHeight()/2
});
$('.box.wide .title').css({
'position' : 'absolute',
'left' : '50%',
'top' : '50%',
'margin-left' : -$('.box.wide .title').outerWidth()/2,
'margin-top' : -$('.box.wide .title').outerHeight()/2
});
【问题讨论】: