1

我正在给 if else 语句一个刺,不确定我是否正确地写了这个......试图得到它,以便如果 popupHeight 尺寸大于 windowHeight 尺寸,那么它将定位到视口的顶部 + 10px ...... </p>

$("#data").load("/content/" + htmlName + ".html", null, function(){
    //Set Variables
    var container = $(".container");
    var project = $(".project");
    var popupWidth = container.find(".project img:first").width();
    var popupHeight = container.find(".project img:first").height()+35;
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var x = ($(window).width() / 2 - popupWidth / 2) + $(window).scrollLeft();
    var y = ($(window).height() / 2 - popupHeight / 2) + $(window).scrollTop();

    //Set popup dimensions
    container.css("width" , popupWidth);
    container.css("height" , popupHeight);

    //Set popup CSS
    container.css({"position": "absolute", "left": x + "px", "z-index": "2" });
    project.css({"width": (popupWidth), "height": (popupHeight) });

    //Determine Position
    if(popupHeight>windowHeight) {
        container.css{("top": $(window).scrollTop(); + 10 + "px") 
        }else{
        container.css({"top": y + "px"});
        return;
        }
});
4

2 回答 2

1

去掉 scrollTop() 之后的分号,放在行尾——

container.css{("top": $(window).scrollTop(); + 10 + "px")

应该看起来像——

container.css({"top": $(window).scrollTop() + 10 + "px"});

你的 css 函数也需要重新格式化,它应该像上面那样。

于 2009-09-16T02:27:08.733 回答
0

我以前从未使用过jQuery,所以我可能是错的,但是这行中的分号是不是放错了地方?

container.css{("top": $(window).scrollTop(); + 10 + "px") 
于 2009-09-16T02:27:21.910 回答