添加浮动:对;到 ul.products-2 li.last
ul.products-2 li.last {
float:right;
margin-right: 0;
}
http://jsbin.com/EjilIdO/2
http://jsbin.com/EjilIdO/2/edit?html,css,js,输出
在加载时或在某些情况下将 javascript 添加到函数中
// no of row
var row = 2;
// no of red item
var red= $('.products-1 li').length;
console.log(red);
// first number to be marked last
var firstnumber = Math.round(red/row)*2+row*row;
// for 2 no of row
/*
if the set is 4, first item will be 8;
if the set is 5, first item will be 10;
if the set is 6, first item will be 10;
if the set is 7, first item will be 12;
*/
/* iterating each li item*/
$( ".products-2 li" ).each(function( index ) {
// as index is started with 0, increment index by 1 and check
// whether it match with firstnumber
// if match, then append last and increment the firstnumber by row*row
// if not match, remove last
if(index+1==firstnumber)
{
$(this).addClass('last');
firstnumber = firstnumber + row*2;
}
else
{
$(this).removeClass('last');
}
});