目前,我正在使用Materialisecss Image Slider。实际上我想要的是保持一个固定的全屏背景图像,文本和图像在固定的背景图像上滑过。
现在,我将滑块类的背景颜色设置为透明,但它不起作用。
$(document).ready(function(){
$('.slider').slider();
});
section {
background: url('http://lorempixel.com/580/250/nature/4') center center no-repeat;
background-size: cover;
}
.slider .slides {
background-color: rgba(255,255,255,0);
margin: 0;
height: 400px;
}
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Materialize slider</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/materialize.css">
</head>
<body>
<section>
<div class="slider">
<ul class="slides">
<li>
<div class="caption center-align">
<h3>This is our big Tagline!</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
<li>
<div class="caption left-align">
<h3>Left Aligned Caption</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
<li>
<div class="caption right-align">
<h3>Right Aligned Caption</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
<li>
<div class="caption center-align">
<h3>This is our big Tagline!</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
</ul>
</div>
</section>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
答案 0 :(得分:2)
最后,我找到了我的问题的答案。
function step(n){
//$(".content-switcher").hide();
if(n==1){
$(".content-switcher").animate({
"left":"-600px"
},"slow");
} else if(n==2){
$(".content-switcher").animate({
"left":"-1200px"
},"slow");
} else if(n==3){
$(".content-switcher").animate({
"left":"0px"
},"slow");
}
}
.container{
width: 600px;
margin: 0 auto;
outline:1px solid red;
overflow: hidden;
background-image: url("https://static.vecteezy.com/system/resources/previews/000/093/696/original/vector-yellow-abstract-background.jpg");
}
.slider{ width: 1800px;}
.content-switcher{
width: 600px;
float: left;
position: relative;
top:0;
left: 0;
}
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Simple Content Slider</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<a href="#" onclick="step(1); return false;" style="color: #fff">Step 1</a>
<a href="#" onclick="step(2); return false;" style="color: #fff">Step 2</a>
<a href="#" onclick="step(3); return false;" style="color: #fff">Step 3</a>
<div class="slider">
<div class="content-switcher" id="content1">
<p>1Lorem ipsum dolor sit amet, consectetur adipisicing elit
. Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437">
<p>1Lorem ipsum dolor sit amet, consectetur adipisicing elit
. Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437">
<p>1Lorem ipsum dolor sit amet, consectetur adipisicing elit
. Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
</div>
<div class="content-switcher" id="content2">
<img src="http://images2.fanpop.com/image/user_images/Starmight350-808191_384_377.jpg">
<p>2Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
</div>
<div class="content-switcher" id="content3">
<p>3Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
</div>
</div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
答案 1 :(得分:1)
如果您处理section
style
属性中的引用问题,似乎可以正常工作。如果您对style=""
使用双引号,则在这些双引号内不能使用双引号。因此,您需要删除该属性中的双引号或用单引号替换它们。另外rgba(255,255,255,0)
是实现透明度的一种方法,但更简单的方法是使用transparent
- 但更简单的方法就是完全删除该行,因为默认情况下没有背景,所以它&#39} ;透明。这是一个有效的演示 - http://codepen.io/anon/pen/MJwOBR
答案 2 :(得分:1)
您可以使用带有覆盖类的div并在整个图像上设置覆盖div,如下所示:
在div
之后添加<section> tag
,并将类名设为class="overlay"
<div class="overlay"></div>
添加一些CSS,以在图片上设置覆盖div
.overlay
{
position: absolute;
height: 100%;
width: 100%;
background-color: rgba(255, 255, 255, 0.17);
}
并添加CSS以正确显示文本
.caption {
position: relative;
z-index: 99;
}
尝试一下。