当链接太多且颜色数组太短时,如何管理数组从 0 重新启动(在函数 get_hover_color 中)?感谢您的帮助!
直到。
<div class="line">
<div><h2 class="color_link">DRUCKVORSTUFE</h2></div>
<div><h2 class="color_link">SCAN</h2></div>
<div><h2 class="color_link">RETUSCHEN</h2></div>
<div><h2 class="color_link">ANDRUCK</h2></div>
<div><h2 class="color_link">PDF</h2></div>
<div><h2 class="color_link">CTP</h2></div>
<div><h2 class="color_link">STACCATO</h2></div>
.............
.............
.............
........and so on........
</div>
function get_hover_color(i){
hover_color_array = ['54cacd','e84d3a','ff3384','a0388d','231599','0d958a','629B39','33811E','F04E00','F00200','D9008F','58dbb4','093C8B','AECB27','E5B208','74204f','C26A21','DB2C17','cccf78','166C64','9A1E6E','7EADC2','00A1CE'];
return hover_color_array[i];
}
$('.color_link').each(function(i){
$(this).hover(
function(){
var $this = $( this );
$this.data( 'prehovercolor', $this.css( 'color' ) ).css( {'color' : '#' + get_hover_color(i), 'cursor' : 'pointer' });
},function(){
var $this = $( this );
$this.css( 'color', $this.data( 'prehovercolor') );
});
});