Prevent object from jumping to center point when dragging starts

I have a script for dragging GameObjects around, but at the moment, whenever I start to drag on the object it jumps to the center the object onto the pointer. What I’d like to achieve is regardless of where I start to drag on the object it initiates drag at that point instead of jumping to the object center first. What do I need to modify in my OnDrag or OnBeginDrag method to achieve this?

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

public class DragHandling : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler
{
	public float partScale;

	[HideInInspector] public Transform placeholderParent = null;
	[HideInInspector] public Transform parentToReturnTo = null;
	[HideInInspector] public GameObject trashCan; 
	[HideInInspector] public GameObject partsPanel;
	[HideInInspector] public GameObject partsWindow;
	[HideInInspector] public GameObject buildBoard;

	GameObject placeholder = null;
	GameObject dragLayer;
	Vector3 buildPanelScale;
	Vector3 partsPanelScale = new Vector3(1.0f, 1.0f, 1.0f);
	Vector3 startPosition;

	// PolygonCollider2D collider;

	void Start ()
	{
		dragLayer = GameObject.FindGameObjectWithTag("DragLayer");
		buildBoard = GameObject.FindGameObjectWithTag("Board");
		partsPanel = GameObject.FindGameObjectWithTag("Parts");
		partsWindow = GameObject.FindGameObjectWithTag("PartsWindow");
		trashCan = GameObject.FindGameObjectWithTag("Trash");

		// collider = transform.GetComponent<PolygonCollider2D>();
	}

	#region IPointerClickHandler implementation

	public void OnPointerClick (PointerEventData eventData)
	{
		if(transform.parent.gameObject == buildBoard)
			transform.SetAsLastSibling();
	}

	#endregion

	#region IBeginDragHandler implementation

	public void OnBeginDrag (PointerEventData eventData)
	{
		// create placeholder gap and hold correct position in layout
		placeholder = new GameObject();
		placeholder.transform.SetParent(transform.parent);
		placeholder.transform.SetSiblingIndex(transform.GetSiblingIndex());
		parentToReturnTo = transform.parent;									// store original parent location
		placeholderParent = parentToReturnTo;									// set placeholder gameobject transform
		startPosition = transform.position;
		GetComponent<CanvasGroup>().blocksRaycasts = false;						// turn off image raycasting when dragging image in order to see what's behind the image			
	}

	#endregion

	#region IDragHandler implementation
	
	public void OnDrag (PointerEventData eventData)
	{
		Vector3 mousePosition = new Vector3(eventData.position.x, eventData.position.y, 0);
		transform.position = Input.mousePosition;											// set object coordinates to mouse coordinates

		if(transform.parent.gameObject == partsPanel)
			transform.SetParent(dragLayer.transform);										// pop object to draglayer to move object out of parts Panel
		if(transform.parent.gameObject == buildBoard)
			transform.SetParent(dragLayer.transform);
	}
	
	#endregion

	#region IEndDragHandler implementation

	public void OnEndDrag (PointerEventData eventData)
	{
		transform.SetParent(parentToReturnTo);									// Snaps object back to orginal parent if dropped outside of a dropzone
		transform.SetSiblingIndex(placeholder.transform.GetSiblingIndex());		// Returns card back to placeholder location
		GetComponent<CanvasGroup>().blocksRaycasts = true;						// turn Raycast back on
		Destroy(placeholder);													// kill the placeholder if object hits a drop zone or returns to parts panel

		if(transform.parent.gameObject == buildBoard)
		{
			buildPanelScale = new Vector3(partScale, partScale, partScale);
			transform.localScale = buildPanelScale;
			transform.SetAsLastSibling();										// always place last piece on top
		}
		if(transform.parent.gameObject == partsPanel)
			transform.localScale = partsPanelScale;
	}

	#endregion

}

your not using your own variable mousePosition, your using Input.mousePosition, but im having same problem. sorry i couldnt help

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

[RequireComponent(typeof(Image))]
public class MobileWindow : MonoBehaviour,IPointerClickHandler,IBeginDragHandler,IDragHandler
{
    Canvas myCanvas;
    Image img;
    Vector2 preClickPos;

    void Awake()
    {
        myCanvas = GetComponentInParent<Canvas>();
        img = GetComponent<Image>();
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        RectTransformUtility.ScreenPointToLocalPointInRectangle(myCanvas.transform as RectTransform, eventData.position, myCanvas.worldCamera, out Vector2 pos);
        preClickPos = pos - img.rectTransform.anchoredPosition;

        // preClickPos = myCanvas.transform.TransformPoint(pos- img.rectTransform.anchoredPosition);
    }

    public void OnDrag(PointerEventData eventData)
    {
        RectTransformUtility.ScreenPointToLocalPointInRectangle(myCanvas.transform as RectTransform, eventData.position, myCanvas.worldCamera, out Vector2 pos);
        img.rectTransform.anchoredPosition = pos - preClickPos;

        // transform.position = myCanvas.transform.TransformPoint(pos- preClickPos);
    }
}

If you do not want to use AnchoredPosition, use double-slashed.
hope this help