简体   繁体   English

当浏览器小于640px时如何将列表项转换为滑块?

[英]how to convert list item to slider when browser is less than 640px?

I want to make it slider with pager and touch enabled only in mobile view. 我想使用仅在移动视图中启用寻呼机和触摸的滑块。 I'm not really familiar how to use jQuery/JavaScript so I hope you guys can help me :) 我不是很熟悉如何使用jQuery / JavaScript所以我希望你们能帮助我:)

HTML: HTML:

<div class="slider">
    <div class="slide"><a href="#"><img src="images/createacct-icon.png" alt=""><span>Create Account</span></a></div>
    <div class="slide"><a href="#"><img src="images/findgame-icon.png" alt=""><span>Find Your Game</span></a></div>
    <div class="slide"><a href="#"><img src="images/createjoin-icon.png" alt=""><span>Create / Join Team</span></a></div>
    <div class="slide"><a href="#"><img src="images/compete-icon.png" height="75" alt=""><span>Compete & Win</span></a></div>
</div>

CSS: CSS:

.slider {
    margin-top: 30px;
    font-family: 'Sintony';
}

.slider .slide {
    float: left;
    width: 22.3%;
    padding: 2% 0;
    background: #191f2e;
    text-align: center;
    font-weight: bold;
    font-size: 13px;
}

.slider .slide:hover {
    background: #151a28;
    transition: background .3s ease;
}

.slider .slide a span {
    color: #c9cbce;
    margin-top: 22px;
    display: block;
}

.slider .slide img {
    display: block;
    margin: 0 auto;
}

.slider .slide:nth-of-type(2),
.slider .slide:nth-of-type(3),
.slider .slide:nth-of-type(4) {
    margin-left: 3.6%;
}

First, make sure you have downloaded the slick library from the link that you provided. 首先,确保已从您提供的链接下载了光滑的库。 The "/slick" folder should be in the same directory as your HTML code. “/ slick”文件夹应与HTML代码位于同一目录中。

Add the following lines to your <head> 将以下行添加到<head>

<link rel="stylesheet" type="text/css" href="slick/slick-theme.css"/>
<link rel="stylesheet" type="text/css" href="slick/slick.css"/>

Add these lines to your <body> to import the library 将这些行添加到<body>以导入库

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="slick/slick.min.js"></script>

Then your code should be: 那你的代码应该是:

 <script>

    resizeWindow();
    window.addEventListener('resize', resizeWindow);
    function resizeWindow(){
        $('.slider').slick({
            responsive: [
                {
                    breakpoint: 2500,
                    settings: "unslick"
                },
                {
                    breakpoint: 640,
                    settings: {
                        dots: true
                  }
                }
            ]
        });
    }

 </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 所选文字在640像素或更小的视口中逐渐消失 - Selected text fades away in a 640px or less viewport 如何使目标宽度和高度大于640像素的高质量PhoneGap摄像机图像? - How can I make PhoneGap Camera images with target width and height bigger than 640px of high quality? 仅为屏幕大于640像素的设备加载图像 - Load images only for devices with > 640px screen 当视口小于 481px 时禁用 slick slider - Disable slick slider when viewport is less than 481px 当浏览器的尺寸小于800px时如何隐藏div - How to hide div when browser resizes to less than 800px 对于网络应用,iPhone 4+默认为320px分辨率,我想使用完整的640px - iPhone 4+ defaults to 320px resolution for web apps, I want to use the full 640px 当我的窗口宽度小于800px时,如何将js滑块效果更改为淡入淡出? - how do i change the js slider effect to fade when my window width is less than 800px? 当项目少于3时,轮播拇指滑块停止克隆 - Carousel thumb slider stop clone when item less than 3 当屏幕尺寸小于480px时,如何禁用jQuery功能? - How do I disable jQuery function when screen size is less than 480px? JavaScript中屏幕分辨率小于767px时的addClass - addClass when the screen resolution is less than 767px in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM