我创建了一个简单的jQuery图像转换查看器,并且每次加载新照片时,窗口自动滚动到刚加载的新图像的顶部。我试图阻止这一点,以便过渡不会中断用户在页面上的任何位置。jquery禁用自动窗口滚动
这是到目前为止我的代码:
$(document).ready(function() {
var slideShow = function()
{
current_img = $("#current_img"); // <img> element with src to be changed
height_width = 'width="100%" height="100%"';
photos = new Array('images/home_s1.png','images/home_s2.png', 'images/home_s3.png');
setTimeout(function() { current_img.fadeOut('fast', function() { current_img.attr('src', photos[0]); current_img.fadeIn('slow'); }); }, 0);
setTimeout(function() { current_img.fadeOut('fast', function() { current_img.attr('src', photos[1]); current_img.fadeIn('slow'); }); }, 5000);
setTimeout(function() { current_img.fadeOut('fast', function() { current_img.attr('src', photos[2]); current_img.fadeIn('slow'); }); }, 10000);
setTimeout(function() { slideShow(); }, 15000);
}
$("img").ready(slideShow);
});
我试图操纵的preventDefault()函数的多种不同的方式,而且我自己也尝试加载图像(即加载到HTML的不同变化( )而不是img.attr('src')),但没有运气...任何有关实现此目的的最有效方式的建议?
你有没有发现这个答案吗? http://stackoverflow.com/questions/1391833/how-to-prevent-window-from-scrolling-up-on-jquery-slidetoggle?rq=1 所有最好 – devanand 2012-08-05 09:21:43