var first = $("#firstImg").offset().left; var second = $("#secondImg").offset().left; var third= $("#thirdImg").offset().left; $(function(){ $("#link span:eq(0)").click(function(){ $("#waku").animate({ scrollLeft: first }, 1000); }); $("#link span:eq(1)").click(function(){ $("#waku").animate({ scrollLeft: second }, 1000); }); $("#link span:eq(2)").click(function(){ $("#waku").animate({ scrollLeft: third }, 1000); }); });