我正在尝试使用CarouFredSel在div中显示不同的图像,这些图像需要在开头隐藏,稍后点击某个按钮时可见。但它没有像我预期的那样工作。但是当我在开始时将div设置为可见时,那么我可以隐藏并显示这个div没有问题。 所以我在寻找是否有人可以帮我解决隐藏和显示CarouFredSel div的问题。
.wrapper {
background-color: white;
width: 92%;
margin: 10px auto;
padding: 50px;
box-shadow: 0 0 5px #999;
display:none;
}
.list_carousel {
background-color: #ccc;
margin: 0 0 30px 30px;
width: 95%;
}
.list_carousel ul {
margin: 0;
padding: 0;
list-style: none;
display: block;
}
.list_carousel li {
font-size: 40px;
color: #999;
text-align: center;
width: 140px;
height: 42px;
padding: 0;
margin-left: 3px;
margin-right: 3px;
margin-top: 6px;
margin-bottom: 6px;
display: block;
float: left;
}
.clearfix {
float: none;
clear: both;
}
.prev {
float: left;
margin-left: 10px;
}
.next {
float: right;
margin-right: 10px;
}
<body>
<div class="wrapper">
<div class="list_carousel">
<ul id="foo2">
<li>
<img src="images/itcells.png" s alt="" />
</li>
<li>
<img src="images/itcells.png" alt="" />
</li>
<li>
<img src="images/itcells.png" alt="" />
</li>
<li>
<img src="images/itcells.png" alt="" />
</li>
<li>
<img src="images/itcells.png" alt="" />
</li>
</ul>
<div class="clearfix"></div> <a id="prev2" class="prev" href="#"><</a>
<a id="next2" class="next"
href="#">></a>
</div>
<br />
</div>
<input type="button" id="hide" />
<input type="button" id="show" />
</body>
$(document).ready(function () {
$('#show').click(function () {
$(".wrapper").animate({
"opacity": "show"
}, 1000);
});
$('#hide').click(function () {
$(".wrapper").animate({
"opacity": "hide"
}, 1000);
});
});
$(function () {
//Scrolled by user interaction
$('#foo2').carouFredSel({
auto: false,
prev: '#prev2',
next: '#next2',
pagination: "#pager2",
mousewheel: true,
swipe: {
onMouse: true,
onTouch: true
}
});
});
请帮我展示和隐藏div。
答案 0 :(得分:3)
为了完成这项工作,我改变了一些事情(使用jsFiddle示例,教程后链接):
结果就是这样。
<div class="wrapper">
<ul id="foo2">
<li><img src="http://placehold.it/100x100"/></li>
<li><img src="http://placehold.it/100x100"/></li>
<li><img src="http://placehold.it/100x100"/></li>
<li><img src="http://placehold.it/100x100"/></li>
<li><img src="http://placehold.it/100x100"/></li>
<li><img src="http://placehold.it/100x100"/></li>
<li><img src="http://placehold.it/100x100"/></li>
<li><img src="http://placehold.it/100x100"/></li>
</ul>
<a id="prev2" class="prev" href="#"><</a>
<a id="next2" class="next" href="#">></a>
</div>
<input type="button" id="hide" value="hide" />
<input type="button" id="show" value="show" />
.wrapper {
height: 100px;
position: relative;
background - color: white;
margin: 10px auto;
padding: 50px;
box - shadow: 0 0 5px #999;display:none;}
.clearfix {float: none;clear: both;}
.prev {position: absolute;z-index: 9;top: 50%;left:10px;}
.next {position: absolute;z-index: 9;top: 50%;right:10px;}
# foo2 {margin: 0;padding: 0;}
#foo2 li {
display: block;
float: left;
height: 100px;
text - align: center;
width: 100px;
color: #8cabbf;display: block;}
# foo2 li img {border: 1px solid#dfe9ee;}
$(document).ready(function () {
$('#show').click(function () {
$(".wrapper").animate({
"opacity": "show"
}, 1000);
generateCarousel();
});
$('#hide').click(function () {
$(".wrapper").animate({
"opacity": "hide"
}, 1000);
});
function generateCarousel() {
// Scrolled by user interaction
$('#foo2').carouFredSel({
auto: false,
responsive: false,
items: {
visible: 3,
width: 100
},
width: 600,
prev: '#prev2',
next: '#next2',
pagination: "#pager2",
swipe: {
onMouse: true,
onTouch: true
}
});
}
});
<强> Here is a working demo. 强>