0
我想做一个视差滚动教程(http://net.tutsplus.com/tutorials/html-css-techniques/simple-parallax-scrolling-technique/)。我无法通过jQuery获取背景位置CSS。我已经能够推断滚动处理程序没有被调用。我有这个警告,当我滚动时不会触发:jQuery的滚动没有被触发
$(window).scroll(function(){
alert('Handler for scroll called');
});
当我在此函数之外执行警报时,它会被调用。所以我知道jQuery被调用的权利(这是一个.ready()函数)。有任何想法吗?
编辑
我甚至无法手动调用滚动处理。例如,这个工程:
$('*').click(function(){
alert('handler called');
});
但这并不:
$('*').click(function(){
$(window).scroll();
}); // Remember I set an alert up above for when the scroll handler was called
第二个编辑,全js文件:
$(document).ready(function(){
$('section[data-type="background"]').each(function(){
var $bgobj = $(this); // assigning the object
$(window).scroll(function() {
var yPos = -($window.scrollTop()/$bgobj.data('speed'));
// Put together our final background position
var coords = '50% '+ yPos + 'px';
// Move the background
$bgobj.css({ backgroundPosition: 50% 10 });
});
});
$(window).on('scroll',function(){
alert('Handler for scroll called');
});
$('*').click(function(){
$(window).scroll();
});
});
你确定你在滚动窗口吗? – adeneo
你发布 - 应该工作--http://jsfiddle.net/mohammadadil/UeBMR/1/ –
@adeneo我滚动。我认为这是窗口,我没有其他任何东西像div或任何设置滚动。 – smilebomb