缓存其他页面的背景滚动图像位置
cache background scrolling image position for other pages
我正在开发一个具有滚动背景图像的网站。当我转到网站上的另一个页面时,动画从开头开始。有没有办法缓存位置,以便当我转到另一个页面时,动画从中断的地方继续?
这是我正在使用的代码
<head>
<style>
body{
width:100%;
}
#pageWrap{
width:100%;
position:absolute;
background:#96c7ec;
}
#contentTop{
width:100%;
height:545px;
background:url('../img/bbClouds.png') repeat-x;
border-bottom:5px solid #41260c;
}
</style>
</head>
<body>
<div id="pageWrap">
<div id="contentTop"></div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
var scrollSpeed = 70; // Speed in milliseconds
var step = 1; // How many pixels to move per step
var current = 0; // The current pixel row
var imageWidth = 1500; // Background image width
var headerWidth = 1500; // How wide the header is.
//The pixel row where to start a new loop
var restartPosition = -(imageWidth - headerWidth);
function scrollBg(){
//Go to next pixel row.
current -= step;
//If at the end of the image, then go to the top.
if (current == restartPosition){
current = 0;
}
//Set the CSS of the header.
$('#contentTop').css("background-position",+current+"px 0px");
}
//Calls the scrolling function repeatedly
var init = setInterval("scrollBg()", scrollSpeed);
</script>
</body>
任何帮助或指示非常感谢
谢谢
你使用这个jQuery cookie插件。
用法
-
设置值:
$.cookie('the_cookie', 'the_value');
-
检索值:
$.cookie('the_cookie');
$(window).unload
事件添加一个事件侦听器,然后设置 cookie 背景位置,然后在 $(window).load
上获取 cookie 并设置背景位置。
作为旁注,我建议你使用内置在jQuery核心中的.animate
:
var startAnimate = function() {
$('#contentTop')
.css('background-position', 0)
.animate({ backgroundPosition: imageWidth },
{ duration: 3000, complete: startAnimate });
};
startAnimate();
相关文章:
- 背景图像顶部的滚动图像不移动
- 可单击滚动图像以显示文本框
- 使用JS滑动或滚动图像
- 在手机上缩小/缩放滚动图像
- 如何在滑块中重复滚动图像
- Django应用程序中的滚动图像
- 滚动图像下的内容而不会中断
- 视差滚动图像超出视野
- 如何使用jquery滚动图像
- 如何在 js 和 css3 中使用鼠标光标单击实现滚动图像
- 如何在不使用选框标签的情况下滚动图像?Javascript,jquery或css任何东西
- 使用 jQuery 滚动图像墙
- 在jquery中滚动图像时需要动画
- 滚动图像
- 滚动图像,单击时显示可移动的弹出窗口
- 为什么不是'我的滚动图像无法正常工作
- 在fullpage.js中使用幻灯片切换向下滚动图像
- 视差滚动图像通过徽标透明度
- 当使用滚动图像提交表单时,我的验证将被忽略
- 只有一个按钮可以滚动图像,我该如何进行排列