Jquery计数器和fadein问题

时间:2015-10-03 22:56:40

标签: javascript jquery html css slider

嗨我正在尝试创建一个滑块,当我旋转幻灯片时,底部的圆圈和计数器会改变颜色。此外,当我选择它时,滑块将跳转到该幻灯片。我想知道最好的方法是什么?由于某种原因,Lorempixel.com不会出现在代码段中。

另外,为什么右箭头的fadein功能无法正常工作?谢谢!



'use strict';

$( document ).ready(function() {


    var total = 11;

    for(var i=1; i < total; i++){
        /*$('#slideshow .pics').append('<img src="http://lorempixel.com/500/300/food/'+i+'" />');
        $('#slideshow .pics').append('<b>Slide ' + i + '</b>.'); //add text to slide*/

        $('#slideshow .inner-pics').append('<div class="slide-' + i + '">');
        $('#slideshow .inner-pics div:last').append('<img src="http://lorempixel.com/500/300/food/' + i + '" />');
        $('#slideshow .inner-pics div:last').append('<b>Slide ' + i + '</b>.'); //add text to slide
        $('#slideshow .inner-pics').append('</div>');
        $('.circle').append('<i class="fa fa-circle">-</i>');
    }

    var Pictures;

    function slideAnimationLeft(targetLeft) {
        Pictures = $('.inner-pics');

        $(function() {
            Pictures.children('div:first').animate({
                'margin-left': targetLeft + 'px'
            }, 1000, function() {
                Pictures.children('div:first').appendTo(Pictures).css('margin-left', '0px').fadeIn(2000);
            });
        });
    };


    function slideAnimationRight(targetRight) {
        Pictures = $('.inner-pics');

        $(function() {
            Pictures.children('div:first').animate({
                'margin-right': targetRight + 'px'
            }, 1000, function() {
                Pictures.children('div:first').appendTo(Pictures).css('margin-right', '0px').fadeIn(2000);
            });
        });
    };

    $('.left >').click(function() { slideAnimationLeft(-500) } );
    $('.right >').click(function() { slideAnimationRight(500) } );

});
&#13;
/* http://meyerweb.com/eric/tools/css/reset/
   v2.0 | 20110126
   License: none (public domain)
*/
/* line 6, ../sass/_reset.scss */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */
/* line 27, ../sass/_reset.scss */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
  display: block;
}

/* line 31, ../sass/_reset.scss */
body {
  line-height: 1;
}

/* line 34, ../sass/_reset.scss */
ol, ul {
  list-style: none;
}

/* line 37, ../sass/_reset.scss */
blockquote, q {
  quotes: none;
}

/* line 40, ../sass/_reset.scss */
blockquote:before, blockquote:after,
q:before, q:after {
  content: '';
  content: none;
}

/* line 45, ../sass/_reset.scss */
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* line 50, ../sass/_reset.scss */
* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

/* line 6, ../sass/styles.scss */
#slideshow {
  width: 500px;
  height: 300px;
  margin: 0 auto;
  overflow: hidden;
  margin-top: 10%;
}
/* line 13, ../sass/styles.scss */
#slideshow > img {
  position: absolute;
  display: block;
}
/* line 18, ../sass/styles.scss */
#slideshow .pics {
  z-index: 1;
}
/* line 21, ../sass/styles.scss */
#slideshow .pics div {
  position: relative;
  float: left;
}
/* line 25, ../sass/styles.scss */
#slideshow .pics div b {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.8);
  padding: 30px;
}
/* line 39, ../sass/styles.scss */
#slideshow .inner-pics {
  width: 7000px;
}
/* line 43, ../sass/styles.scss */
#slideshow .control {
  z-index: 2;
}
/* line 47, ../sass/styles.scss */
#slideshow > div {
  width: 500px;
  height: 300px;
  overflow: hidden;
  position: absolute;
}

/* line 55, ../sass/styles.scss */
.circle {
  text-align: center;
}

/* line 61, ../sass/styles.scss */
i.fa-circle {
  opacity: 0.7;
  margin-top: 20%;
  padding: 2px;
}

/* line 69, ../sass/styles.scss */
i.fa-angle-left {
  margin-top: 20%;
  opacity: 0.7;
  z-index: 100;
}

/* line 77, ../sass/styles.scss */
i.fa-angle-right {
  margin-top: 20%;
  margin-left: 87.75%;
  opacity: 0.7;
  z-index: 100;
}
&#13;
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Assignment 2</title>
    <link rel="stylesheet" href="stylesheets/styles.css">
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div id="slideshow">
    <div class="control">
        <a href="#" class="left"><i class="fa fa-angle-left fa-5x left"></i></a>
        <a href="#" class="right"><i class="fa fa-angle-right fa-5x right"></i></a>

        <div class="circle">
        </div>

    </div>
    <div class="pics">
        <div class="inner-pics">

        </div>
    </div>
</div>

<script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="bower_components/jquery-ui/jquery-ui.js"></script>
<script type="text/javascript" src="main.js"></script>


</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

制作类似http://jsfiddle.net/o5ad4gk0/1/

的内容
TabControl