const scrollContainer = document.querySelector('.head-box')
const activeItem = document.querySelector('.head-title-one')
const containerRect = scrollContainer.getBoundingClientRect()
const itemRect = activeItem.getBoundingClientRect()
const itemLeft = itemRect.left - containerRect.left
const itemRight = itemRect.right - containerRect.left
const containerWidth = containerRect.width
const scrollLeft = scrollContainer.scrollLeft
if (itemLeft < 0) {
scrollContainer.scrollTo({ left: scrollLeft + itemLeft, behavior: 'smooth' })
} else if (itemRight > containerWidth) {
scrollContainer.scrollTo({ left: scrollLeft + itemRight - containerWidth, behavior: 'smooth' })
}
```
```