Phone Game UI and camera rotation

Hello Guys,
I have a question about camera rotation and UI. So i create camera rotation and scroll bar but every time i scroll it the camera rotating following the mouse or hand input. So the question is how do i scroll without rotating the camera ?

here the code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class camerarotation : MonoBehaviour
{
    [SerializeField]
    private Camera cam;
    [SerializeField]
    private Transform target;
    private Vector3 previousPos;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            previousPos = cam.ScreenToViewportPoint(Input.mousePosition);
        }
        if (Input.GetMouseButton(0))
        {
            Vector3 direction = previousPos - cam.ScreenToViewportPoint(Input.mousePosition);
            //Vector3 mtm = new Vector3(target.position.x + 2,target.position.y,target.position.z);
            cam.transform.position = target.position;//new Vector3();
            cam.transform.Rotate(new Vector3(5,0,0),direction.y * 180);
            cam.transform.Rotate(new Vector3(0,5,0),-direction.x * 180, Space.World);
            cam.transform.Translate(new Vector3(0,0,-10));
            previousPos = cam.ScreenToViewportPoint(Input.mousePosition);

        }
    }
}

thank you in advance.

When you do the GetMouseDown, check if you are over an UI object with a raycast. If you are, disable rotation until until you GetMouseButtonUp. Should take care of the problem.