导航根据当前点击焦点滚动
作者:互联网
<div id="xm_title" style="background:#fff;width:100%;overflow-y:scroll;white-space: nowrap;">
<span class="typeBox" style="display:inline-block;background:#eee;color:#888;border-radius:5px;padding:0 10px;margin:0 5px;font-size:13px" onclick="click_type(this)">菜单一</span>
<span class="typeBox" style="display:inline-block;background:#eee;color:#888;border-radius:5px;padding:0 10px;margin:0 5px;font-size:13px" onclick="click_type(this)">菜单二</span>
</div>
var moveX = $(obj).position().left + $(obj).parent().scrollLeft();
var pageX = document.documentElement.clientWidth; //设备的宽度
var blockWidth = $(obj).width();
var left = moveX - (pageX / 2) + (blockWidth / 2);
$("#xm_title").animate({ scrollLeft: left }, 500);
标签:blockWidth,滚动,scrollLeft,moveX,点击,var,obj,导航,left 来源: https://www.cnblogs.com/hxlj130520/p/15166610.html