Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Really simple jQuery slider
Prev
Next
css
body { margin: 0; position: relative; } .slider { max-width: 800px; } .slider__images { opacity: 0; visibility: hidden; position: relative; top: 0px; left: 0px; list-style-type: none; transition: opacity .4s ease-in, visibility .4s ease-in; } .slider__images.loaded { opacity: 1; visibility: visible; } .slider__images-item { position: absolute; top: 0px; left: 0px; } .no-js .slider__images-item:first-of-type { position: relative; } .no-js .slider__images-item:not(:first-of-type) { display: none !important; } .slider__images-image { display: block; } .slider__controls { margin-top: 30px; user-select: none; text-align: center; } .slider__control { display: inline-block; color: #829995; cursor: pointer; } .slider__control--prev { margin-right: 10px; } .slider__control--next { margin-left: 10px; } .slider__pagers { display: inline-block; margin: 0; padding: 0; list-style-type: none; } .slider__pagers li { display: inline-block; margin: 0 5px; cursor: pointer; color: #829995; padding: 0 10px; } .slider__pagers li.active { color: #333; } body { background: #EF629F; background: linear-gradient(to right, #EF629F, #EECDA3); font-family: Avenir, 'Proxima Nova', sans-serif; font-weight: normal; line-height: 1.5; } ul, ol, div { margin: 0; padding: 0; } img { max-width: 100%; } h1 { margin-top: 30px; color: #fff; font-size: 18px; font-weight: normal; letter-spacing: 4px; text-transform: uppercase; } .wrapper { padding: 30px; } .header, .footer { margin: auto; max-width: 800px; text-align: center; color: #fff; } .header a, .footer a { color: #fff; } .footer { margin-top: 30px; } .slider { margin: 30px auto 0; padding: 30px; background: white; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); }
JavaScript
// create pager list items var sliderImage = $('.slider__images-image'); sliderImage.each(function (index) { $('.js__slider__pagers').append('
'+(index+1)+'
'); }); // set up vars var sliderPagers = 'ol.js__slider__pagers li', sliderPagersActive = '.js__slider__pagers li.active', sliderImages = '.js__slider__images', sliderImagesItem = '.slider__images-item', sliderControlNext = '.slider__control--next', sliderControlPrev = '.slider__control--prev', sliderSpeed = 5000, lastElem = $(sliderPagers).length-1, sliderTarget; // add css heigt to slider images list function checkImageHeight() { var sliderHeight = $('.slider__images-image:visible').height(); $(sliderImages).css('height', sliderHeight+'px'); }; sliderImage.on('load', function() { checkImageHeight(); $(sliderImages).addClass('loaded') }); $(window).resize(function(){ checkImageHeight(); }); // set up first slide $(sliderPagers).first().addClass('active'); $(sliderImagesItem).hide().first().show(); // transition function function sliderResponse(sliderTarget) { $(sliderImagesItem).fadeOut(300).eq(sliderTarget).fadeIn(300); $(sliderPagers).removeClass('active').eq(sliderTarget).addClass('active'); } // pager controls $(sliderPagers).on('click', function() { if ( !$(this).hasClass('active') ) { sliderTarget = $(this).index(); sliderResponse(sliderTarget); resetTiming(); } }); // next/prev controls $(sliderControlNext).on('click', function() { sliderTarget = $(sliderPagersActive).index(); sliderTarget === lastElem ? sliderTarget = 0 : sliderTarget = sliderTarget+1; sliderResponse(sliderTarget); resetTiming(); }); $(sliderControlPrev).on('click', function() { sliderTarget = $(sliderPagersActive).index(); lastElem = $(sliderPagers).length-1; sliderTarget === 0 ? sliderTarget = lastElem : sliderTarget = sliderTarget-1; sliderResponse(sliderTarget); resetTiming(); }); // slider timing function sliderTiming() { sliderTarget = $(sliderPagersActive).index(); sliderTarget === lastElem ? sliderTarget = 0 : sliderTarget = sliderTarget+1; sliderResponse(sliderTarget); } // slider autoplay var timingRun = setInterval(function() { sliderTiming(); }, sliderSpeed); function resetTiming() { clearInterval(timingRun); timingRun = setInterval(function() { sliderTiming(); }, sliderSpeed); }
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>简单的jQuery滑块-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号