【发布时间】:2014-03-27 00:49:56
【问题描述】:
我一直在使用一些 javascript 来实现我想要的视差滚动。直到现在我才在 22 英寸 iMac 上看到它,而且我知道它的像素高度会成为一个问题,尤其是对于本网站的风格而言。
HTML 使用带有 CSS 的部分:
.pages {
min-height: 1050px;
height: 1050px;
margin: 0 auto;
width: 100%;
min-width: 1024px;
position: relative;
}
脚本:
$(document).ready(function(){
// Cache the Window object
$window = $(window);
$('section[data-type="background"]').each(function(){
var $bgobj = $(this); // assigning the object
$(window).scroll(function() {
// Scroll the background at var speed
// the yPos is a negative value because we're scrolling it UP!
var yPos = -( ($window.scrollTop() - $bgobj.offset().top) / $bgobj.data('speed'));
// Put together our final background position
var coords = '50% '+ yPos + 'px';
$bgobj.css({
backgroundPosition: coords,
'-webkit-background-size': 'cover',
'-moz-background-size': 'cover',
'-o-background-size': 'cover',
'background-size': 'cover'
});
}); // window scroll Ends
});
});
/*
* Create HTML5 elements for IE's sake
*/
document.createElement("article");
document.createElement("section");
所以,如果有人可以帮助我解决这两个/任何一个问题:
如何使部分的高度为用户屏幕的 100%?简单地将 height 和 min-height 更改为 100% 不会这样做 - 部分“消失”。
是否可以更改此脚本,以便从图像的中心(高度)而不是从左上角调整图像的大小?
【问题讨论】:
标签: jquery css scroll parallax screen-resolution