弹出功能在chrome中返回错误的值

时间:2014-04-05 21:23:48

标签: javascript google-chrome

function popup(a, b) {
    x = document.getElementById(a);
    y = document.getElementById('ze-editor').offsetWidth;
    if (x.style.display == 'none') {
        position = (b.offsetX === undefined) ? b.layerX - 50 : b.offsetX - 50;
        position = Number(position);
        console.log(b.layerX - 50);
        x.setAttribute('style', 'display: block');
        if (position + x.offsetWidth + 20 > y) {
            position = position - 40;
        }
        x.style.left = position + 'px';
    } else {
        x.style.display = 'none';
    }
    $('#' + a).siblings().hide();
};

此代码适用于firefox,控制台日志为我提供了正确的值#34; position"在firefox和chrome上。但是当谈到x.style.left时,它给了我一个不同的价值?例如,我的b.layerX-50是249但是当弹出窗口出现时,它的左边值是-37? Jsfiddle:http://jsfiddle.net/7Q6D5/

0 个答案:

没有答案