简体   繁体   English

单击复选框后,如何从页面上其他位置的div浮动到该复选框旁边?

[英]How can I make a div from elsewhere on the page float next to a checkbox when the checkbox is clicked?

I have a checkbox. 我有一个复选框。 I want a div which is on the bottom of my page to float next to the checkbox when the checkbox has been clicked. 我希望单击复选框后,位于页面底部的div浮动在复选框旁边。

How can I do this? 我怎样才能做到这一点?

Here is some code that is working for my mouseovers. 这是一些适用于我的鼠标悬停的代码。 Its pretty far beyond my level. 它远远超出了我的水平。 Is there an easier way, or way I can use this code for checkboxes as well? 有没有更简单的方法,或者我也可以将此代码用于复选框?

function addreflinkpreview(e) {
var c;
var d = "srcElement";
var f = "href";
this[f] ? c = this : c = e[d];
ainfo = c.className.split('|');
var g = document.createElement('div');
g.setAttribute("id", "preview" + c.className);
g.setAttribute('class', 'reflinkpreview');
g.setAttribute('className', 'reflinkpreview');
if (e.pageX) {
    g.style.left = '' + (e.pageX + 50) + 'px'
} else {
    g.style.left = (e.clientX + 50)
}
var h = document.createTextNode('');
g.appendChild(h);
var i = c.parentNode;
var j = i.insertBefore(g, c);
new Ajax.Request(ku_boardspath + '/read.php?b=' + ainfo[1] + '&t=' + ainfo[2] + '&p=' + ainfo[3] + '&single',{
    method: 'get',
    onSuccess: function(a) {
        var b = a.responseText || _("something went wrong (blank response)");
        j.innerHTML = b
    },
    onFailure: function() {
        alert('wut')
    }
})

} }

One way you may be able to achieve this is with positioning and transitions. 您可能能够实现这一目标的一种方法是定位和过渡。 Take the screen coordinates of the click event and then absolute position the div next to the coordinate by adding or subtracting from the x-coordinate. 取得click事件的屏幕坐标,然后通过在x坐标上增加或减去,将div绝对定位在该坐标旁边。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM