Reputation: 21
I want to change the position of div during run time. i have taken two div. id is Div1 and Div2. Div2 is by default false. whenever user click on div1 div2 is visible and after user press the mouse down key on Div2 and drag, then position of the div2 will be change. position will be similar to cursor position. Whenever user up the mousekeyup then div2s position is similar to cursor position. in sort when user drag the corsor then div2 automatically drag with cursor and user stop the drag then div2s position is same as cursor position. So how to apply the cursor position to div2 position using only java script.withot jquery.
Upvotes: 0
Views: 2170
Reputation: 6124
You can change the position and visibility of elements by changing their style attributes.
To make an element invisible, change its style.display property from "block" to "none"
element.style.display = "none";
To move elements around, change their style.left and style.top properties.
element.style.left = leftVal + "px";
element.style.top = topVal + "px";
Hope that helped!
Upvotes: 1