Показать сообщение отдельно
  #2 (permalink)  
Старый 15.08.2016, 16:23
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

hujak_hujak,

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <style type="text/css">
    #slider{
    position: relative;
    width: 100%;
    height: 400px;
    overflow: hidden;
}
.img{
    position: absolute;
    width: 100%;
    height: 400px;
    left: 100%;
}
.img:nth-of-type(1){
    background-color: green;

}
.img:nth-of-type(2){
    background-color: grey;
}
.img:nth-of-type(3){
    background-color: darkcyan;
}
.img:nth-of-type(4){
    background-color: darkkhaki;
}
.active{
    left:0;
}

#butRight,#butLeft{
    z-index: 200;
    position: absolute;
    top:200px;
    width: 40px;
    height: 40px;
    background-color: yellow;
}
#butRight{
    right: 5px;
}
#butLeft{
    left: 5px;
}
  </style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(window).load(function() {
    var item = $(".img"),
        i = 0,
        len = item.length;
    $("#butRight, #butLeft").on("click", function(event) {
        event.preventDefault();
        i += this.id == "butRight" ? 1 : -1;
        i == -1 && (i = len - 1);
        i == len && (i = 0);
        item.removeClass("active").eq(i).addClass("active")
    })
});
</script>


</head>

<body>

<body>
<div id="slider">
    <a href="" id="butRight"></a>
    <a href="" id="butLeft"></a>
    <div class="img active"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
</div>
</body>


</body>

</html>
Ответить с цитированием