Pregunta

Le doy una puñalada a las declaraciones if else, no estoy seguro de si estoy escribiendo esto correctamente ... Intentando obtenerlo de manera que si la dimensión popupHeight sea más grande que la dimensión windowHeight, entonces la colocaría en la parte superior de la ventana gráfica + 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;
        }
});
¿Fue útil?

Solución

Deshágase del punto y coma después de scrollTop () y colóquelo al final de la línea-

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

Debería verse como-

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

Su función CSS también necesita ser reformateada, debería gustarle lo anterior.

Otros consejos

Nunca he usado jQuery antes, así que podría estar equivocado, pero ¿no está el punto y coma en esta línea en el lugar equivocado?

container.css{("top": $(window).scrollTop(); + 10 + "px") 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top