jQuery와 CSS를 혼합하여 사용하면 모래 아래에있는 모래를 페이지 아래로 스크롤 할 때 흐리게 표시하려고합니다. 기본적으로 두 개의 '모래'이미지가 있고 jQuery를 사용하여 사용자가 스크롤 할 때 컨테이너의 높이를 변경합니다.jQuery 코드가 Safari에서 작동하지만 Firefox는 작동하지 않습니다.
<!-- Load jQuery -->
<script src="jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<!-- Handle Hourglass Scrolling -->
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
// Set value of topStart and bottomStart to equal to y-position of the equivilent divs
var topStart = parseInt($('#top-sand').css('top'));
var bottomStart = parseInt($('#bottom-sand').css('top'));
// Calculate the maximum height of the sand relative to the window size
var sandHeight = $(window).height()*0.22;
// setValues sets positions based on window size
function setValues() {
topStart = parseInt($('#top-sand').css('top'));
bottomStart = parseInt($('#bottom-sand').css('top'));
sandHeight = $(window).height()*0.22;
var hourglassWidth = $('#hourglass #outline img').css('width');
var leftMargin = $(window).width()*0.5+ 320;
$('#top-sand').height(22+"%");
$('#top-sand img').height(sandHeight)
$('#bottom-sand img').height(sandHeight)
$('#hourglass').css({left:leftMargin+"px"})
$('#trace').text(hourglassWidth)
// contentMarginLeft = $('#hourglass #outline').width();
// $('#content').text(contentMarginLeft);
// css({"margin-left": contentMarginLeft + "px"});
};
setValues();
// This listens for a window scroll event and then handles the height and position of the sand in the Hourglass
$(window).scroll(function() {
// Calculating the position of the scrollbar
var doc = $("body"),
scrollPosition = $("body").scrollTop(),
pageSize = $("body").height(),
windowSize = $(window).height(),
fullScroll = pageSize - windowSize;
percentageScrolled = (scrollPosition/fullScroll);
// Calculating the Y-positions of the two sand piles
var topPosition = topStart+(22*percentageScrolled);
var bottomPosition = bottomStart-(22*percentageScrolled);
// Updating the sand piles
$('#top-sand').height(22-(22*percentageScrolled)+"%")
.css({top: topPosition+"%"});
$('#bottom-sand').height(22*percentageScrolled+"%")
.css({top:bottomPosition+"%"});
});
// This listens for a window resize event and then reconfigures the layout
$(window).bind('resize', function() {
// Reconfigure layout
});
});
</script>
그것은 사파리에서 잘 작동하고있어
(모든 너무 자주 글리치가 비록 여기서 상단 이미지 변경의 높이 있지만, y 위치입니다하지 않습니다)하지만 전혀 파이어 폭스에서 작동되지 않았습니다 . 여기에서 사이트를 볼 수 있습니다 http://www.chris-armstrong.com/ticktalk
저는 jQuery를 처음 접했기 때문에 완전히 멍청한 오류라고 사과합니다.
미리 감사드립니다.
코드 블록. – sberry
괜찮아요 (감사 cmcculloh) –
쪽 메모 (귀하의 문제에 대한 답변이 아닌), _ALWAYS_ 기수를 지정 parseInt()를 사용하면 그렇지 않으면 나중에 아주 힘들어 디버그 버그로 실행됩니다 : parseInt ('123', 10) parseInt ('123') 대신 javascript에 불행한 "feature"가있어서, 당신이 그것을 지정하지 않으면 기수를 자동으로 감지합니다. –