It is possible to move states and establish custody over children however you must meet certain requirements. Most states have some variation of the Uniform Child Custody Jurisdiction and Enforcement Act (UCCJEA). In fact, most states follow this rule except for Massachusetts and Vermont.
The UCCJEA permits a court to make a decision regarding child custody if certain tests are met. These requirements are listed in descending order of importance and not all of them need to be met, it is a balancing test.
First, the state must be the child's "home state." A child's home state is established if he or she resided in the state with the parent for at least six months or the child did reside with his or her parent but is absent because he or she was removed by the other parent.
Second, the child must have "significant connections" with people who reside in the state. These connections can be anyone including: family, friends, teachers, doctors, psychologists and more. Essentially you want to produce as much evidence as possible that the child has grown up and developed a life in the state.
Third, the child is residing in the state for safety reasons. Principally this means that the child was removed to the state to escape abuse or neglect by the other parent or guardian.
Finally, no other state can fulfill one of the three tests listed above. Occasionally more than one state will meet at least one of the tests but if that state declines the case, then the new state may become the "home" of the child. The state may decline the case, for example, in cases of abuse by the other parent.
If you are considering moving out of state while there is an active or pending child custody order then you may want to consider consulting with an attorney. As you can see, there are specific requirements that must be fulfilled to establish the child's "home state" for custody purposes. Failure to abide by these rules could put your rights to custody or visitation time at risk.