因为宽度自动设置为视口的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