2009-09-16 4 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

+0

코드가 작동하지 않는다고 생각합니다 ... – RageZ

+0

if 및 else 부분이 작동하지 않고 구문 오류가 발생했습니다 ... – antonanton

답변

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")