how do i move a UI slider with mouse position

i want to move a UI slider to follow the position of the mouse anywhere on the screen with out intractable being enabled

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

public class mouseToSlider : MonoBehaviour {

    float mx; //calculated x position of mouse
    float xMax; //max value mx can get, required for calculation

    Slider slider;

	// Use this for initialization
	void Start () {
        slider = GetComponent<Slider>(); //get attached slider script
        xMax = Camera.main.pixelWidth;   //max value mx can get is width of cam
	}
	
	// Update is called once per frame
	void Update () {
        mx = Input.mousePosition.x; //get mouse x
        mx = mx / xMax;             //find ratio, get value between 1 and 0
        slider.value = mx;          //slider.value can get value between 1 and 0
	}
}