简体   繁体   English

JavaScript slider 未按预期工作

[英]JavaScript slider not working as expected

I am using Sly library for sliding a couple of divs.我正在使用 Sly 库来滑动几个 div。 I am following their syntax:我遵循他们的语法:

 <div id="wrapperSly">
        <div class="frame" id="weatherSlider">
            <div id="slidee">
                {{#each forecast.data}}
                    <div id="0hrs">
                        <div id="0time">{{this.hour}}</div>
                        <div id="0currTemp">{{this.temp}}&deg</div>
                    </div>
                {{/each}}
            </div>
        </div>
    </div>
        // js file:
        let slyFrame = $('#weatherSlider');
        let $slidee = $('#slidee');
        let $wrap = slyFrame.parent();
        //  slyFrame.sly(false);
        // Call Sly on frame
        slyFrame.sly({
            horizontal: 1,
            itemNav: 'basic',
            smart: 1,
            activateOn: 'click',
            mouseDragging: 1,
            touchDragging: 1,
            releaseSwing: 1,
            startAt: 3,
            scrollBy: 1,
            activatePageOn: 'click',
            speed: 300,
            elasticBounds: 1,
            easing: 'easeOutExpo',
            dragHandle: 1,
            dynamicHandle: 1,
            clickBar: 1
        }).init();

It almost works, the problem is that if I put 10 divs, for example, there are 9 divs next to each other ( working as expected ), but the last one is below the first.它几乎可以工作,问题是如果我放置 10 个 div,例如,有 9 个 div 彼此相邻(按预期工作),但最后一个低于第一个。 The same happens if I put 6 divs, for example.例如,如果我放置 6 个 div,也会发生同样的情况。 5 are one next to each other and the last one is below. 5个彼此相邻,最后一个在下方。

This is probably a css issue - you need to set margins to 0 to make the items fit the container like this:这可能是 css 问题 - 您需要将边距设置为 0 以使项目适合容器,如下所示:

.frame { width: 100%; height: 160px; padding: 0; }
.frame .slidee { margin: 0; padding: 0; height: 100%; list-style: none; }
.frame .slidee li { float: left; margin: 0 5px 0 0; padding: 0; width: 120px; height: 100%; }

What's your css look like?你的 css 是什么样的?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM