【问题标题】:having trouble position my arrows with unslider jQuery plugin无法使用 unslider jQuery 插件定位我的箭头
【发布时间】:2014-03-25 03:01:01
【问题描述】:

我按照 unslider 的文档开发了一个带有点和箭头的滑块。

我已经按照我想要的方式工作了点,但是我遇到了一些问题。

我没有成功将左箭头对齐到滑块的左侧,将右箭头对齐到滑块的右侧。我已经做了很多测试,但没有任何效果。

你知道我们如何使用 unslider 插件来做到这一点吗?

我正在尝试什么: http://jsfiddle.net/jcak/RJqw8/

我的html:

<section id="banner-container">

    <div class="banner">

        <ul>
           <li style="background-color:red;  height:500px;">This is another slide.</li>
            <li style="background-color:green;  height:500px;">This is another slide.</li>
           <li style="background-color:blue;  height:500px;">This is another slide.</li>   
        </ul>
        <a href="#" class="unslider-arrow prev"></a>
        <a href="#" class="unslider-arrow next"></a>
    </div>

</section>

我的 CSS:

  #banner-container
    {
        width:100%;
        float:left;
    }


    .banner
    {   position: relative; 
        overflow: auto;
        width: 100%;
    }

    .banner li
    {
        list-style:none;
        background-repeat:no-repeat;
        background-size:cover;
    }

    .banner ul li
    { 
        float: left;
    }

    .banner ul li img
    {   width:100%;
        height:220px;
    }
    .banner .dots 
    {   margin-left:50%;
        bottom: 10px;
        left: 0;
        position: absolute;
        right: 0;
        display:none;
    }

    .banner:hover .dots 
    {
        display:block;
    }

    .banner .dots li
    { 
        border: 2px solid #fff;
        border-radius: 6px;
        cursor: pointer; 
        display: inline-block;
        height: 10px;
        margin: 0 4px;
        opacity: .4; 
        text-indent: -999em; 
        -webkit-transition: background .5s, opacity .5s;
        -moz-transition: background .5s, opacity .5s;
        transition: background .5s, opacity .5s; width: 10px;
    }

    .banner .dots li.active 
    { 
        background: #fff;
        opacity: 1;
    }

.arrows .prev {
    position: relative;
    top: -136px;
}
.arrows .next {
    position: absolute;
    right: 0;
    top: 109px;
}

我的 jQuery:

$(function() {
    $('.banner').unslider({

        speed: 2000,
        delay: 2000,
        fluid: true,
        dots: true,
        arrows: true,
        pause: true


    });
});

【问题讨论】:

    标签: javascript jquery slider slideshow jquery-ui-slider


    【解决方案1】:

    您面临的问题是您的 CSS 代码没有处理 s,因为它们具有不同的类名。两种选择:

    #1 - 切换 CSS 文件中的类名:

    .unslider-arrow.prev {...}
    .unslider-arrow.next {...}
    

    #2 - 将 s 中的类切换为您在 CSS 文件中使用的类:

    <a href="#" class="arrow prev"></a>
    <a href="#" class="arrow next"></a>
    

    但是,当使用第二个选项时,您必须将 CSS 中的关系更改为:

    .arrow.prev {}
    .arrow.next {}
    

    【讨论】:

    • 感谢您的回答和更正!但即使有了这个更正,问题仍然存在,但一切似乎都很好,我真的不明白问题出在哪里!
    • 我自己检查了一下,这是一个 jsfiddle:jsfiddle.net/zc39D/2(忽略滑块不再工作,尝试了一些东西)-左右定位正确,但您的库似乎正在混合搞事情..
    • 谢谢你..它的工作原理!我没有放 .unslider-arrow{} 的代码。
    • 真的感谢codezombie!顺便说一句,您知道如何将这些箭头的图像更改为我想要的图像吗?因为 unslider 文档不要谈论这个!
    • 嘿@CesarM - 我不太确定如何更改图标。但是当您将一些文本添加到箭头容器中时,您会看到仍然出现箭头。我建议你应该看看你的滑块库的 css 表,也许它们是在那里定义的。当你弄清楚它们的设置位置时,只需更改它们;-) 你可能会感兴趣的是:weloveiconfonts.com
    【解决方案2】:

    请查看我的 unslider.com 示例 html 文件:

        <!-- The HTML -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    
        <head>
        <title>Unslider.com example</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> 
        <script src="http://unslider.com/unslider.min.js"type="text/javascript"></script>
    
            <!-- JavaScript -->
    
        <script type="text/javascript">
    
    $(function() {
    $('.banner').unslider({
        speed: 500,               //  The speed to animate each slide (in milliseconds)
        delay: 3000,              //  The delay between slide animations (in milliseconds)
        complete: function() {},  //  A function that gets called after every slide animation
        keys: true,               //  Enable keyboard (left, right) arrow shortcuts
        dots: true,               //  Display dot navigation
        fluid: false              //  Support responsive design. May break non-responsive designs
    
    });
    var unslider = $('.banner').unslider();
    
      $('.prev').click(function() {
          unslider.data('unslider').prev();
      });
    
      $('.next').click(function() {
          unslider.data('unslider').next();
      });
      return false;
    });
    </script>
    
        <!-- CSS -->
        <style type="text/css">
    
    * { 
      margin: 0;
      padding: 0;
      -webkit-box-sizing: border-box; 
    }
    
    .banner {
    position: relative;
    width: 100%;
    overflow: auto;
    top: 50px;
    /*z-index: -1;*/
    
    font-size: 18px;
    line-height: 24px;
    text-align: center;
    
    color: #FFFFFF;
    text-shadow: 0 0 1px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.3);
    
    background: #FFFFFF;
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
    }
    .banner ul {
    list-style: none;
    width: 300%;
    }
    .banner ul li {
    display: block;
    float: left;
    
    min-height: 500px;
    
    -o-background-size: 100% 100%;
    -ms-background-size: 100% 100%;
    -moz-background-size: 100% 100%;
    -webkit-background-size: 100% 100%;
    background-size: 100% 100%;
    
    box-shadow: inset 0 -3px 6px rgba(0,0,0,.1);
    }
    
    .banner .inner {
    padding: 360px 0 110px;
    
    float: left;
    vertical-align:-100px;
    }
    
    .banner h1, .banner h2 {
    
    font-size: 40px;
    line-height: 52px;
    color: #fff;
    }
    
    .banner .btn {
    display: inline-block;
    margin: 25px 0 0;
    padding: 9px 22px 7px;
    clear: both;
    
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    text-transform: uppercase;
    text-decoration: none;
    border : rgba(255, 255, 255, 0.4) solid 2px;
    border-radius: 5px;
    }
    .banner .btn:hover {
    background : rgba(255, 255, 255, 0.05);
    }
    .banner .btn:active {
    -webkit-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
    -moz-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
    -ms-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
    -o-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
    filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
    }
    
    .banner .btn, .banner .dot {
    -webkit-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
    -moz-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
    -ms-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
    -o-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
    }
    
    .banner .dots {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 20px;
    width: 100%;
    }
    .banner .dots li {
    display: inline-block;
    
    width: 10px;
    height: 10px;
    line-height: 10px;
    margin: 0 4px;
    
    text-indent: -999em;
    
    
    border: 2px solid #fff;
    border-radius: 6px;
    
    cursor: pointer;
    opacity: .4;
    
    -webkit-transition: background .5s, opacity .5s;
    -moz-transition: background .5s, opacity .5s;
    transition: background .5s, opacity .5s;
    }
    .banner .dots li.active {
    background: #fff;
    opacity: 1;
    }
    
    
    
    
    .unslider-arrow {
      font-family: Expressway;
      font-size: 50px;
      text-decoration: none;
      color: #3d3d3d;
      background: rgba(255,255,255,0.7);
      padding: 0 20px 5px 20px;
    }
    
    .next {
      position: absolute;
      top: 65%;
      right: 0  
    }
    
    .prev {
      position: absolute;
      top: 65%;
      right: 90 /* change to left:0; if u wanna have arrow on left side */ 
    }
    </style>
         </head>
        <!-- Body of HTML document -->
    
        <body>
            <div class="slider">
            <div class="banner">
              <ul>
              <li style="background-image: url('http://lorempixel.com/1200/600/');">
                <div class="inner">
                  <h1>Some h1 text</h1>
                 <p>smaller p text</p>
    
                    <a class="btn" href="http://www.yourlink.com">Hyperlink</a>
                </div>
              </li>
    
              <li style="background-image: url('http://lorempixel.com/1200/600/');">
                <div class="inner">
                  <h1>Some h1 text</h1>
                 <p>smaller p text</p>
    
                  <a class="btn" href="http://www.yourlink.com">Hyperlink</a>
                  </div>
                  </li>
    
               <li style="background-image: url('http://lorempixel.com/1200/600/');">
                 <div class="inner">
                  <h1>Some h1 text</h1>
                 <p>smaller p text</p>
    
                  <a class="btn" href="http://www.yourlink.com">Hyperlink</a>
                  </div>
              </li>
    
              <li style="background-image: url('http://lorempixel.com/1200/600/');">
              <div class="inner">
                  <h1>Some h1 text</h1>
                 <p>smaller p text</p>
    
                  <a class="btn" href="http://www.yourlink.com">Hyperlink</a>
                </div>
              </li>
          </ul>
    
    
            </div>
              <a href="#" class="unslider-arrow prev">&larr;</a>
              <a href="#" class="unslider-arrow next">&rarr;</a>
            </div>
       </body>  
    
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 1970-01-01
      • 2018-04-10
      相关资源
      最近更新 更多