【发布时间】:2013-12-07 18:36:09
【问题描述】:
我有一个函数,我知道这不是编写它的最有效方式,不仅对于这个函数,而且对于将来的其他函数。
除了一个数字在每次重复时都会得到 += 1 之外,它是相同的行,所以我确信有一个 for 或 if 或每种方式来循环它并同时减少代码并提高可维护性。
function lines() {
$('#bottom-1').lazylinepainter(
{
"svgData": pathObj1, //only line that changes
"strokeWidth": 1,
"strokeColor": "#fff"
}).lazylinepainter('paint');
$('#bottom-2').lazylinepainter(
{
"svgData": pathObj2, //only line that changes
"strokeWidth": 1,
"strokeColor": "#fff"
}).lazylinepainter('paint');
$('#bottom-3').lazylinepainter(
{
"svgData": pathObj3, //only line that changes
"strokeWidth": 1,
"strokeColor": "#fff"
}).lazylinepainter('paint');
$('#bottom-4').lazylinepainter(
{
"svgData": pathObj4, //only line that changes
"strokeWidth": 1,
"strokeColor": "#fff"
}).lazylinepainter('paint');
$('#solutions h2').delay( ).animate({opacity:'1'}, 1000, 'easeInQuint')
}
【问题讨论】: