html 纯JS / jQuery横幅滑块
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 纯JS / jQuery横幅滑块相关的知识,希望对你有一定的参考价值。
contained slider
https://codepen.io/zuraizm/pen/vGDHl
fullwidht slider:
<div id="slider">
<a href="#" class="control_next">>></a>
<a href="#" class="control_prev"><</a>
<ul>
<li class="slide1">
<div class="slide_cont">
<h1 class="black">PERFUME & JEWELRY DISCOVERY BOX</h1>
<p>Only $29.99/month
Get 5 luxury designer perfume samples and a jewelry set,
with bracelet or necklace, locket and 5 collectible charms.</p>
<p><a type="button" class="btn whitebtn" href="/subscription"> GET STARTED</a></p>
</div>
</li>
<li class="slide2">
<div class="slide_cont">
<h2 class="black">Slider 2</h2>
<p>The only monthly perfume subscription
service with luxury designer perfume brands
and silver jewelry.</p>
<p><a type="button" class="btn whitebtn" href="/subscription"> GET STARTED</a></p>
</div>
</li>
</ul>
</div>
<style>
/* TEST SLIDER */
#slider {
position: relative;
overflow: hidden;
margin: 20px auto 0 auto;
border-radius: 4px;
}
#slider ul {
position: relative;
margin: 0;
padding: 0;
height: 200px;
list-style: none;
}
#slider ul li {
position: relative;
display: block;
float: left;
margin: 0;
padding: 0;
/* width: 500px;
height: 300px; */
width: 100%;
height: 533px;
/* background: #ccc; */
text-align: center;
line-height: 300px;
}
a.control_prev, a.control_next {
position: absolute;
top: 40%;
z-index: 999;
display: block;
padding: 3% 1%;
width: auto;
height: auto;
background: rgba(42, 42, 42, 0.35);
color: #fff;
text-decoration: none;
font-weight: 600;
font-size: 18px;
opacity: 0.8;
cursor: pointer;
}
a.control_prev:hover, a.control_next:hover {
opacity: 1;
-webkit-transition: all 0.2s ease;
}
a.control_prev {
border-radius: 0 2px 2px 0;
}
a.control_next {
right: 0;
border-radius: 2px 0 0 2px;
}
.slider_option {
position: relative;
margin: 10px auto;
width: 160px;
font-size: 18px;
}
div#slider {
width: 100% !important;
height: 533px !important;
}
li.slide1 {
background: url(http://d3a1v57rabk2hm.cloudfront.net/perfumesurprise/tasty_mobile/images/f_home.jpg) !important;
background-size: cover;
background-repeat: no-repeat;
}
li.slide2 {
background: url(http://d3a1v57rabk2hm.cloudfront.net/perfumesurprise/tasty_mobile/images/f_home.jpg) !important;
background-size: cover;
background-repeat: no-repeat;
}
.black { color: #000; }
.slide_cont {
padding-top: 10%;
max-width: 775px;
margin: 0 auto;
}
.slide_cont p {
font-size: 24px;
}
</style>
<script>
jQuery(document).ready(function ($) {
var slideCount = $('#slider ul li').length;
var slideWidth = $('#slider ul li').width();
var slideHeight = $('#slider ul li').height();
var sliderUlWidth = slideCount * slideWidth;
$('#slider').css({ width: slideWidth, height: slideHeight });
// commented out for full width sliders, uncomment for contained sliders
//$('#slider ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });
$('#slider ul li:last-child').prependTo('#slider ul');
function moveLeft() {
$('#slider ul').animate({
left: + slideWidth
}, 200, function () { // 200 is the number in microseconds it takes to slide the next image
$('#slider ul li:last-child').prependTo('#slider ul');
$('#slider ul').css('left', '');
});
};
function moveRight() {
$('#slider ul').animate({
left: - slideWidth
}, 200, function () {
$('#slider ul li:first-child').appendTo('#slider ul');
$('#slider ul').css('left', '');
});
};
$('a.control_prev').click(function () {
moveLeft();
});
$('a.control_next').click(function () {
moveRight();
});
});
</script>
以上是关于html 纯JS / jQuery横幅滑块的主要内容,如果未能解决你的问题,请参考以下文章