问题描述
我想改变在运行时div的位置。我已经采取了两个分区。 id是Div1构成和Div2构成。
DIV2默认为false。
每当在DIV1 DIV2用户点击是可见的,之后用户preSS上Div2的和向下拖动鼠标键,然后DIV2的位置将改变。
位置将类似于光标位置。每当用户了mousekeyup然后div2s的地位类似光标的位置。在排序时,用户拖动corsor然后DIV2自动拖动光标和用户停止拖动则div2s位置相同的光标位置。
因此,如何运用光标位置仅使用Java script.withot jQuery来DIV2的位置。
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.
推荐答案
您可以通过改变自己的风格属性改变元素的位置和知名度。
You can change the position and visibility of elements by changing their style attributes.
要做出一个元素无形的,它的style.display财产块为无改变
element.style.display =无;
To make an element invisible, change its style.display property from "block" to "none"element.style.display = "none";
要四处移动元素,改变他们的style.left和style.top属性。
element.style.left = leftVal +PX
element.style.top = topVal +PX
To move elements around, change their style.left and style.top properties.element.style.left = leftVal + "px";element.style.top = topVal + "px";
希望这有助于!
这篇关于如何改变在运行时div的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!