너비가 뷰포트의 100 %가되도록 자동으로 설정되기 때문에 변경하지 않으면 늘어납니다.
사용이 :
$.scrollingParallax('img/clouds.png', {
bgHeight : '250%',
staticSpeed : .25,
staticScrollLimit : false,
bgWidth: 'auto'
});
위의 여기 행동에서 볼 수있다 : 비 뻗어 배경 이미지는 항상 왼쪽 부동 때문에 jsFiddle이
, 나는 이렇게 약간의 jQuery 선 (善)을 채찍질 창 크기 조정 이벤트 중에도 항상 이미지가 뷰포트의 가운데에 배치됩니다. 즉, 이미지는 모든 브라우저에서 가로 세로 비율을 유지하면서 최대 이미지 크기 또는 축소로 확장됩니다.
$(function() {
// Specify your background image here.
var bgMain = 'http://indigobrazilianportuguese.com/2012/wp-content/uploads/Home_bg1600.jpg';
$.scrollingParallax(bgMain, {
bgHeight : '200%',
staticSpeed : 0.25,
staticScrollLimit : false,
// Important to set to 'auto' so Aspect Ratio for width is preserved because height defined above is fixed.
bgWidth: 'auto'
});
// These two lines is for page load.
// The variable will calculate CSS 'left' for the background image to center it in the viewport.
// First, horizontal viewport size is checked via $(window).width()
// Then, image width is determined by searching for image's unique filepath/filename.
// Once the different is known, this value is then divided by 2 so that equal space is seen on left and right side of image which becomes the variable value.
var bgMainHcenter = ($(window).width() - $('body img[src="' + bgMain + '"]').width()) /2 ;
$('body img[src="' + bgMain + '"]').css('left', bgMainHcenter + 'px');
// Just like above, it's repeated during Window Resize Event.
$(window).resize(function() {
bgMainHcenter = ($(window).width() - $('body img[src="' + bgMain + '"]').width()) /2 ;
$('body img[src="' + bgMain + '"]').css('left', bgMainHcenter + 'px');
});
});
여기에 직접보기 :jsFiddle
당신이 몸 배경 및 사용 배경 크기의 이미지를 넣을 경우 : 커버; http://css-tricks.com/perfect-full-page-background-image/ – SVS
너비 또는 높이를 %로 설정할 수 있습니까? – Huangism
+1 잘 쓰여진 질문입니다. – arttronics