전체 화면 이미지 개체를 갖고 싶습니다. 항상 뷰포트 크기에 맞습니다. 이미지 래퍼의 높이는 뷰포트의 높이 여야합니다. 다음 코드를 사용하여이 작업을 수행했습니다.이미지 요소의 전체 화면
var hero = $('#hero');
var win = $(window);
hero.height(win.height());
$(window).resize(function() {
hero.height(win.height());
});
원하는 것은 래퍼 내부의 이미지 요소가 항상 중간에 위치한다는 것입니다. 뷰포트 크기를 축소하면 이미지 요소의 왼쪽과 오른쪽이 숨겨집니다. 나는 다음의 요지 "fullscreenr"에왔다. 나는 나를 위해 그것을 다시 만들려고했지만 작동하지 않습니다.
플러그인은 내가 부모를 선택하면 작동합니다. 저를 위해서는 "주인공"입니다. 선택기를 #hero img
으로 변경하면 올바르게 작동하지 않습니다. 이미지가 늘어나서 이미지가 함께 밀려 나오고 양쪽 바깥 쪽에서 사라지지 않습니다.
/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* www.nanotux.com
*
* Modifications by Chris Van Patten
* http://www.vanpattenmedia.com
* Version 1.5
**/
(function($){
$.fn.fullscreenr = function(options) {
var defaults = { width: 1280, height: 1024, elementID: this.selector };
var options = $.extend({}, defaults, options);
$(document).ready(function() { $(options.elementID).fullscreenrResizer(options); });
$(window).bind("resize", function() { $(options.elementID).fullscreenrResizer(options); });
return this;
}
$.fn.fullscreenrResizer = function(options) {
// Set bg size
var ratio = options.height/options.width;
// Get browser window size
var browserwidth = $(window).width();
var browserheight = $(window).height();
// Scale the image
if ((browserheight/browserwidth) > ratio){
$(this).height(browserheight);
$(this).width(browserheight/ratio);
} else {
$(this).width(browserwidth);
$(this).height(browserwidth * ratio);
}
// Center the image
$(this).css('left', (browserwidth - $(this).width())/2);
$(this).css('top', (browserheight - $(this).height())/2);
return this;
}
})(jQuery);
$('#hero img').fullscreenr({width: 1400, height: 800});
너희들이 나를 도울 수 있기를 바랍니다 :
이
는 코드입니다. 고맙습니다. 변경 사항 경우
나는 나의 대답을 업데이트했다 : 나는 그것이 도움이되기를 바란다. – Banana
Working! 고마워요! – Caspert