开发者

Placing a Div on top of ASP.NET GridView using Javascript

I am currently working on 开发者_Go百科an ASP.net c# project. I am trying to move a div container to be placed on top of an ASP grid view.

If I set in the style sheet top: 100px; it places the div over the top of the grid view which I want. However, the position needs to be done using Javascript. I use the following code to position the div.

var obj = document.getElementById("software_" + id);
obj.style.top = "80px";

If I use the following code it doesn't place the div in the same place that the stylesheet places it, it jumps to underneath the grid view, as if in java script its trying to avoid containers overlapping.

How can I fix this problem so that the Javascript can place the div over the top like the stylesheet is able to.


You probably need to set the z-index: http://www.w3schools.com/cssref/pr_pos_z-index.asp

And the position to absolute: http://www.w3schools.com/cssref/pr_class_position.asp


Found the answer eventually, it was something to do with the positioning of other divs so I had get the mouse position minus so many pixels in order. Below is the Javascript that I used to do the positioning.

$(objs).mousemove(function (e) {
        //alert('X: ' + e.pageX + ' Y: ' + e.pageY + ' ID: ' + id);
        var x = e.pageX;
        var y = e.pageY;

        var posX = x - 180 + "px";
        var posY = y - 150 + "px";
        document.getElementById("software_" + id).style.top = posY;
        document.getElementById("software_" + id).style.left = posX;
        posX = 0;
        posY = 0;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜