无法更改使用视差滚动的图像宽度
Cannot change width of image that uses parallax scrolling
我无法更改使用从教程中复制的视差滚动代码的图像的宽度。我知道在这个图像示例中,div框和图像也没有完全对齐,但由于某种原因,我没有使用壁纸大小的图像,因为它太大了,所以作为一个示例,它完全对齐,所以不用担心div间距问题。
Jsfidle-https://jsfiddle.net/fouvdjm8/1/
HTML代码
<html>
<!doctype html>
<head>
<title>Parallax Scrolling Tutorial</title>
<!-- CSS Code -->
<link rel="stylesheet" href="style.css">
<!-- JS Code -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<!-- Section #1 -->
<section id="home" data-speed="10" data-type="background">
<article></article>
</section>
<div id="box"></div>
</body>
</html>
CSS代码
body{
margin:0;
padding:0;
}
#home {
background: url(http://webneel.com/wallpaper/sites/default/files/images/01-2014/23-animation-wallpaper.preview.jpg) 50% 0 no-repeat fixed;
height: 1000px;
margin: 0 auto;
width: 100%;
max-width: 1920px;
position: relative;
}
#box {
height: 1000px;
width: auto;
background-color: blue;
}
JS代码
$(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.data('speed'));
// Put together our final background position
var coords = '50% '+ yPos + 'px';
// Move the background
$bgobj.css({ backgroundPosition: coords });
}); // window scroll Ends
});
});
你的css主页类应该看起来像这个
#home {
background: url(http://webneel.com/wallpaper/sites/default/files/images/01-2014/23-animation-wallpaper.preview.jpg) no-repeat center 0 fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 1000px;
margin: 0 auto;
width: 100%;
max-width: auto;
position: relative;
}
相关文章:
- 背景图像顶部的滚动图像不移动
- 可单击滚动图像以显示文本框
- 使用JS滑动或滚动图像
- 在手机上缩小/缩放滚动图像
- 如何在滑块中重复滚动图像
- Django应用程序中的滚动图像
- 滚动图像下的内容而不会中断
- 视差滚动图像超出视野
- 如何使用jquery滚动图像
- 如何在 js 和 css3 中使用鼠标光标单击实现滚动图像
- 如何在不使用选框标签的情况下滚动图像?Javascript,jquery或css任何东西
- 使用 jQuery 滚动图像墙
- 在jquery中滚动图像时需要动画
- 滚动图像
- 滚动图像,单击时显示可移动的弹出窗口
- 为什么不是'我的滚动图像无法正常工作
- 在fullpage.js中使用幻灯片切换向下滚动图像
- 视差滚动图像通过徽标透明度
- 当使用滚动图像提交表单时,我的验证将被忽略
- 只有一个按钮可以滚动图像,我该如何进行排列