2009-09-16 76 views
1

我給了if else語句一個刺,不知道我是否正確寫這個......嘗試獲取它,以便如果popupHeight維度大於windowHeight維度,那麼它會將它置於頂端視+ 10px的...Div定位

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

是什麼問題? – stimms 2009-09-16 01:56:58

+0

我認爲是代碼不工作... – RageZ 2009-09-16 01:58:48

+0

如果和其他部分的代碼不工作,我得到一個語法錯誤... – antonanton 2009-09-16 02:06:24

回答

1

獲取scrollTop的(後)去掉分號,並把它放在線 - 結束

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

看起來應該喜歡 -

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

你的css函數也需要重新格式化,它應該像上面那樣。

0

我從來沒有使用jQuery之前,所以我可能是錯的,但不是在這一行中的分號在錯誤的地方?

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