領域の幅と高さを明示的に設定する必要があります。
水平スクロールについては、次のリンクを確認してください: http://valums.com/scroll-menu-jquery/
スクリプトは次のとおりです。
$(function(){
//Get our elements for faster access and set overlay width
var div = $('div.sc_menu'),
ul = $('ul.sc_menu'),
// unordered list's left margin
ulPadding = 15;
//Get menu width
var divWidth = div.width();
//Remove scrollbars
div.css({overflow: 'hidden'});
//Find last image container
var lastLi = ul.find('li:last-child');
//When user move mouse over menu
div.mousemove(function(e){
//As images are loaded ul width increases,
//so we recalculate it each time
var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
div.scrollLeft(left);
});
});
基本的に、新しいアイテムを追加するときにulWidth
andを更新する必要があります。divWidth
次に、背景画像を水平方向に繰り返すように設定するだけで、設定が完了します。
ul.sc_menu {background:transparent url(image.png) repeat scroll 0 0;height:100px}
注: 高さを設定する必要があります。そうしないと、li が浮かんでいるため、背景が表示されません。