Div定位

时间:2009-09-16 01:52:29

标签: jquery html position

我正在给if else语句一个刺,不确定我是否写得正确...试图得到它,如果popupHeight维度大于windowHeight维度,那么它会将它定位到视口的顶部+ 10px ......

$("#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;
        }
});

2 个答案:

答案 0 :(得分:1)

在scrollTop()之后摆脱分号并将其放在行尾 -

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

应该看起来像 -

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

你的css功能也需要重新格式化,它应该如上所述。

答案 1 :(得分:0)

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

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