Camera follow mouse, remain inside bounds?

Hi, I’m making a 2D sidescroller game, and I’m trying to write a script that allows the camera to move in conjunction with the mouse, but only within the bounds. Imagine I have a “target” object in the center of the screen. When I move my mouse above the camera bound, the camera smoothly move to a higher spot, but with a limit.

I currently have the camera follow the mouse movement :

function Update ()
{
    transform.position = Input.mousePosition;
}

But I can’t figure out how to restrain the camera movement so that it has a limit to how far it can stretch from a “target”. How can I do this in javascript? Thanks for all the help!

Restrict the position of your camera to the bounds

if(Input.MousePosition.x>leftBound && Input.MousePosition.x<rightBound)
    camera.position.x = Input.MousePosition.x;
else if(Input.mousePosition.x > rightBound)
    camera.position.x = rightBound;
else if(Input.mousePosition.x<leftBound)
    camera.position.x = leftBound;