我在萤火虫控制台中收到此错误,无法找出原因。我的代码如下:

$(document).ready(function(){
    var header = $('h2#chase');
    var headerOffset = header.offset();
    header.css({
        "position" : "absolute",
        "left" : headerOffset.left+"px",
        "top" : headerOffset.top+"px"
    });

    var headerSize = {width: header.width(), height: header.height()};
    var headerBounds = {top: headerOffset.top, right: headerOffset.left + headerSize.width, bottom: headerOffset.top + headerSize.bottom, left: headerOffset.left};
    var windowBounds = {top: 0, right: $(window).width() - headerSize.width, bottom: $(window).height() - headerSize.height, left: 0};
    var maxLeft = $(window).width() - headerSize.width;
    var maxTop = $(window).height() - headerSize.height;

    var margin = 30;

    $(window).mousemove(function(e){
        headerOffset = header.offset();
        headerBounds = {top: headerOffset.top, right: headerOffset.left + headerSize.width, bottom: headerOffset.top + headerSize.height, left: headerOffset.left};
        var sides = whichSides(e.pageX, e.pageY);
        $.each(sides, function(key, value) {
            header.css({
                value.side : value.newValue+"px"
            })
        });
    });

    function whichSides(mouseX, mouseY) {
        var sides = [];
        var sideOffsets = {top: headerBounds.top - mouseY, right: mouseX - headerBounds.right, bottom: mouseY - headerBounds.bottom, left: headerBounds.left - mouseX};
        var newValues = {top: mouseY + margin, right: mouseX - margin, bottom: mouseY - margin, left: mouseX + margin};
        $.each(sideOffsets, function(key, value) {
            if (value < 30 && value >= 0) {
                sides.push({side: key, newValue: newValues[key]});
            }
        });
        return sides;
    }
});


错误Firebug返回:

    missing : after property id (line 24, col 9)
    value.side : value.newValue+"px"


编辑:很抱歉,我似乎发布了今天早上写的草稿中的代码,此后我用真正错误的代码对其进行了更新。

最佳答案

在此位:

header.css({
    value.side : value.newValue+"px"
})


value.side不是位于:左侧的有效构造

我不确定您要做什么,但是应该在以下方面做更多工作:

header.css({
    side : value.newValue+"px"
})


阅读您的评论后,您可以执行以下操作:

var o = {}

o[value.side] = value.newValue+'px';

header.css(o);

关于javascript - 缺少:属性ID之后(jQuery),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11395249/

10-12 22:38