Add automatic scaling for video
This commit is contained in:
parent
1409c13e30
commit
315b03f737
@ -168,17 +168,33 @@ $(document).ready(function() {
|
|||||||
else if (image.css("height") !== "100%")
|
else if (image.css("height") !== "100%")
|
||||||
image.css("height", "100%").css("width", "auto").css("position", "").css("bottom", "");
|
image.css("height", "100%").css("width", "auto").css("position", "").css("bottom", "");
|
||||||
}
|
}
|
||||||
|
function scaleVideo() {
|
||||||
|
var video, container;
|
||||||
|
video = $("#video");
|
||||||
|
if (video.get(0) === this)
|
||||||
|
$(window).bind("resize", scaleVideo);
|
||||||
|
container = $("#photo-view");
|
||||||
|
if (video.attr("width") > container.width() && container.height() * video.attr("ratio") > container.width())
|
||||||
|
video.css("width", container.width()).css("height", container.width() / video.attr("ratio")).parent().css("height", container.width() / video.attr("ratio")).css("margin-top", - container.width() / video.attr("ratio") / 2).css("top", "50%");
|
||||||
|
else if (video.attr("height") > container.height() && container.height() * video.attr("ratio") < container.width())
|
||||||
|
video.css("height", container.height()).css("width", container.height() * video.attr("ratio")).parent().css("height", "100%").css("margin-top", "0").css("top", "0");
|
||||||
|
else
|
||||||
|
video.css("height", "").css("width", "").parent().css("height", video.attr("height")).css("margin-top", - video.attr("height") / 2).css("top", "50%");
|
||||||
|
}
|
||||||
function showPhoto() {
|
function showPhoto() {
|
||||||
var width, height, photoSrc, videoSrc, previousPhoto, nextPhoto, nextLink, text;
|
var width, height, photoSrc, videoSrc, previousPhoto, nextPhoto, nextLink, text;
|
||||||
|
|
||||||
if (currentPhoto.mediaType == "video") {
|
if (currentPhoto.mediaType == "video") {
|
||||||
width = currentPhoto.size[0];
|
width = currentPhoto.size[0];
|
||||||
height = currentPhoto.size[1];
|
height = currentPhoto.size[1];
|
||||||
|
$(window).unbind("resize", scaleVideo);
|
||||||
|
$(window).unbind("resize", scaleImage);
|
||||||
videoSrc = photoFloat.videoPath(currentAlbum, currentPhoto);
|
videoSrc = photoFloat.videoPath(currentAlbum, currentPhoto);
|
||||||
$("#video")
|
$("#video")
|
||||||
.attr("width", width).attr("height", height).attr("ratio", currentPhoto.size[0] / currentPhoto.size[1])
|
.attr("width", width).attr("height", height).attr("ratio", currentPhoto.size[0] / currentPhoto.size[1])
|
||||||
.attr("src", videoSrc)
|
.attr("src", videoSrc)
|
||||||
.attr("alt", currentPhoto.name);
|
.attr("alt", currentPhoto.name)
|
||||||
|
.on('loadstart', scaleVideo);
|
||||||
$("#video-box-inner").css('height', height + 'px').css('margin-top', - height / 2);
|
$("#video-box-inner").css('height', height + 'px').css('margin-top', - height / 2);
|
||||||
$("#photo-box").hide();
|
$("#photo-box").hide();
|
||||||
$("#video-box").show();
|
$("#video-box").show();
|
||||||
@ -193,6 +209,7 @@ $(document).ready(function() {
|
|||||||
width = width / height * maxSize;
|
width = width / height * maxSize;
|
||||||
height = maxSize;
|
height = maxSize;
|
||||||
}
|
}
|
||||||
|
$(window).unbind("resize", scaleVideo);
|
||||||
$(window).unbind("resize", scaleImage);
|
$(window).unbind("resize", scaleImage);
|
||||||
photoSrc = photoFloat.photoPath(currentAlbum, currentPhoto, maxSize, false);
|
photoSrc = photoFloat.photoPath(currentAlbum, currentPhoto, maxSize, false);
|
||||||
$("#photo")
|
$("#photo")
|
||||||
|
Loading…
Reference in New Issue
Block a user