在 unslider 中使用箭头

Posted

技术标签:

【中文标题】在 unslider 中使用箭头【英文标题】:Using arrows in unslider 【发布时间】:2014-04-28 00:23:37 【问题描述】:

我正在使用 unslider 进行滑块显示,但遇到了问题,滑块显示运行良好,我将点:真和箭头:真,我希望每个箭头都位于图像的极端。 点看起来很好,但箭头看起来很奇怪,如下图所示:

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

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


    );
);

【问题讨论】:

你能发一个jsfiddle.net这个吗? 是的..它在这里:jsfiddle.net/ritz/bdmU4 Ups 图片不起作用我会尝试将图片也放入 jsfiddle! jsfiddle.net/ritz/bdmU4/1 我放背景色是因为我不能放图片。正如你所看到的,圆点看起来不错,箭头并没有像我想要的那样出现在图像的极端! 【参考方案1】:

请查看我的 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><img src="http://lorempixel.com/1200/600/"   /></li> 
            <li><img src="http://lorempixel.com/1200/600/"   /></li>
            <li><img src="http://lorempixel.com/1200/600/"   /></li>
            <li><img src="http://lorempixel.com/1200/600/"   /></li>
         </ul>
        </div>
          <a href="#" class="unslider-arrow prev">&larr;</a>
          <a href="#" class="unslider-arrow next">&rarr;</a>
        </div>
   </body>  

</html>  

确保&lt;head&gt; 部分中有您下面的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>

【讨论】:

以上是关于在 unslider 中使用箭头的主要内容,如果未能解决你的问题,请参考以下文章

是否可以将 JQuery 'unslider' 配置为仅更改背景?

简单轮播制作

bootstrap框架用了unslider插件为啥图片不能拉伸呢?不是响应式的?怎么搞呢?

vue引入jq插件

如何为幻灯片添加图例? (解压器)

点击页面任何位置返回