Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 07.03.2018, 10:54
Интересующийся
Отправить личное сообщение для Сергей74rus Посмотреть профиль Найти все сообщения от Сергей74rus
 
Регистрация: 25.02.2015
Сообщений: 12

Создание слайдов
Добрый день,немогу решить проблему,не удается распределить данные с бд по слайдам по нажатию кнопки т.е. 1 слайд Игорь студент круто 2 слайд олег выпускник замечательно и т.д. kihore и Albus Чисто для примера как это должно работать
пытался реализовать вот так но не получилось https://jsfiddle.net/v4d1a4va/1/
Ответить с цитированием
  #2 (permalink)  
Старый 07.03.2018, 11:40
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

Сергей74rus,
вероятно алгорит такой, сохранить слайды до инициализации, по клику удалить слайд, изменить, вставить обратно.
Ответить с цитированием
  #3 (permalink)  
Старый 07.03.2018, 12:27
Профессор
Отправить личное сообщение для Dilettante_Pro Посмотреть профиль Найти все сообщения от Dilettante_Pro
 
Регистрация: 27.11.2015
Сообщений: 2,899

<style>
.testimonial{
 background: #fff;
 text-align: center;
 padding: 40px 20%;
 border-radius: 5px;
}
.testimonial .pic{
 width: 70px;
 height: 70px;
 border-radius: 50%;
 overflow: hidden;
 margin: 0 auto;
}
.testimonial .pic img{
 width: 100%;
 height: auto;
 filter: grayscale(100%);
}
.testimonial .testimonial-title{
 font-size: 16px;
 color: #9e9e9e;
 letter-spacing: 3px;
 text-transform: uppercase;
 margin-bottom: 0;
}
.testimonial .post{
 display: block;
 font-size: 12px;
 font-style: italic;
 color: #bcbcbc;
 margin-top: 10px;
 text-transform: uppercase;
}
.testimonial .description{
 font-size: 15px;
 font-style: italic;
 color: #86868a;
 line-height: 1.8;
 margin-top: 10px;
}
.owl-theme .owl-controls{
 width: 100%;
 position: absolute;
 top: 45px;
}
.owl-theme .owl-controls .owl-buttons div{
 font-size: 18px;
 background: transparent;
 opacity: 0.5;
}
.owl-theme .owl-prev{
 position: relative;
 left: -45px;
}
.owl-theme .owl-next{
 position: relative;
 right: -45px;
}
.owl-prev:before,
.owl-next:before{
 content: "\f177";
 font-family: 'FontAwesome';
 color: #444;
}
.owl-next:before{
 content: "\f178";
}
@media only screen and (max-width: 480px){
 .testimonial{
 padding: 40px 10%;
 }
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.transitions.css"> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>
<button id="button">подгрузить данные</button>


<div class="container">
  <div class="row">
    <div class="col-md-offset-2 col-md-8">

      <div id="testimonial-slider" class="owl-carousel">
        <div class="testimonial">
          <div class="pic">
            <img src="http://bootstraptema.ru/snippets/slider/2016/testimonials/testimonials-1.jpg" alt="">
          </div>
          <h3 class="testimonial-title"> Kihore </h3>
          <small class="post"Web Master></small>
          <p class="description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          </p>
        </div>

 <div class="testimonial">
          <div class="pic">
            <img src="http://bootstraptema.ru/snippets/slider/2016/testimonials/testimonials-1.jpg" alt="">
          </div>
          <h3 class="testimonial-title"> Albus </h3>
          <small class="post"Web></small>
          <p class="description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
          </p>
        </div>






      </div>
      <!-- ./owl-carousel -->
    </div>
    <!-- ./col-md-offset-2 col-md-8 -->
  </div>
  <!-- ./row -->
</div>
<!-- ./container -->
<script>
$(document).ready(function() {
  $("#testimonial-slider").owlCarousel({
    items: 1,
    itemsDesktop: [1000, 1],
    itemsDesktopSmall: [979, 1],
    itemsTablet: [767, 1],
    pagination: false,
    transitionStyle: "fade",
    navigation: true,
    navigationText: ["", ""],
    autoPlay: false
  });
});
$('#button').click(function() {
  var $slide = $('.testimonial');
  $pic = $slide.find('#pic');
  $div_name = $('.testimonial-title');
  $div_stat = $('.post');
  $div_desc = $('.description');


      var res = [{
        0: "1",
        1: "Игорь",
        2: "Студент",
        3: "Круто",
        ID: "1",
        Name: "Игорь",
        status: "Студент",
        comment: "Круто"
      }, {
        0: "2",
        1: "Олег",
        2: "Выпускник",
        3: "Замечательно",
        ID: "2",
        Name: "Олег",
        status: "Выпускник",
        comment: "Замечательно"
      }]
      var uscont = $('.owl-wrapper').html();
      if (uscont.trim().length != 0) {
        var $last = $(".owl-item").last()
        $($last).clone().appendTo(".owl-wrapper");

      };
      res.forEach(function(value) {
        for (var key in value) {
          if (Number(key) !== parseFloat(key)) {
            if (key == "Name") {
              $div_name[value["0"] - 1].append(value[key])
            } else if (key == "status") {
              $div_stat[value["0"] - 1].append(value[key])
            } else {
              $div_desc[value["0"] - 1].append(value[key])
            }


          }

    }
  });
});
</script>

Последний раз редактировалось Dilettante_Pro, 07.03.2018 в 12:32.
Ответить с цитированием
  #4 (permalink)  
Старый 07.03.2018, 14:08
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

OwlCarousel add
Сергей74rus,
Вариант для OwlCarousel2 с использованием api слайдера




<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title></title>

  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.css">
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.theme.default.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.theme.green.css" />
  <style type="text/css">
    .testimonial{
 background: #fff;
 text-align: center;
 padding: 40px 20%;
 border-radius: 5px;
}
.testimonial .pic{
 width: 70px;
 height: 70px;
 border-radius: 50%;
 overflow: hidden;
 margin: 0 auto;
}
.testimonial .pic img{
 width: 100%;
 height: auto;
 filter: grayscale(100%);
}
.testimonial .testimonial-title{
 font-size: 16px;
 color: #9e9e9e;
 letter-spacing: 3px;
 text-transform: uppercase;
 margin-bottom: 0;
}
.testimonial .post{
 display: block;
 font-size: 12px;
 font-style: italic;
 color: #bcbcbc;
 margin-top: 10px;
 text-transform: uppercase;
}
.testimonial .description{
 font-size: 15px;
 font-style: italic;
 color: #86868a;
 line-height: 1.8;
 margin-top: 10px;
}
.owl-theme .owl-controls{
 width: 100%;
 position: absolute;
 top: 45px;
}
.owl-theme .owl-controls .owl-buttons div{
 font-size: 18px;
 background: transparent;
 opacity: 0.5;
}
.owl-theme .owl-prev{
 position: relative;
 left: -45px;
}
.owl-theme .owl-next{
 position: relative;
 right: -45px;
}
.owl-prev:before,
.owl-next:before{
 content: "\f177";
 font-family: 'FontAwesome';
 color: #444;
}
.owl-next:before{
 content: "\f178";
}
@media only screen and (max-width: 480px){
 .testimonial{
 padding: 40px 10%;
 }
}


</style>


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.js"></script>
<script>

$(function() {
    var item = $(".testimonial");
    $("#testimonial-slider").owlCarousel({
        items: 1,
        nav: true
    });
    $("#button").click(function() {
        var res = [{
        0: "1",
        1: "Игорь",
        2: "Студент",
        3: "Круто",
        ID: "1",
        Name: "Игорь",
        status: "Студент",
        comment: "Круто"
      }, {
        0: "2",
        1: "Олег",
        2: "Выпускник",
        3: "Замечательно",
        ID: "2",
        Name: "Олег",
        status: "Выпускник",
        comment: "Замечательно"
      }];
        res.forEach(function(value, i) {
            $("#testimonial-slider").owlCarousel("remove", 0);
            var $last = item.eq(i).clone();
            $div_name = $last.find(".testimonial-title");
            $div_stat = $last.find(".post");
            $div_desc = $last.find(".description");
            for (var key in value) {
                if (Number(key) !== parseFloat(key)) {
                    if (key == "Name") {
                        $div_name.append(value[key]);
                    } else {
                        if (key == "status") {
                            $div_stat.append(value[key]);
                        } else {
                            $div_desc.append(value[key]);
                        }
                    }
                }
            }
        $("#testimonial-slider").owlCarousel("add", $last).owlCarousel("update");
        });
    });
});

</script>


</head>

<body>

<button id="button">подгрузить данные</button>


<div class="container">
  <div class="row">
    <div class="col-md-offset-2 col-md-8">

      <div id="testimonial-slider" class="owl-carousel">
        <div class="testimonial">
          <div class="pic">
            <img src="http://bootstraptema.ru/snippets/slider/2016/testimonials/testimonials-1.jpg" alt="">
          </div>
          <h3 class="testimonial-title"> Kihore </h3>
          <small class="post"Web Master></small>
          <p class="description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          </p>
        </div>

 <div class="testimonial">
          <div class="pic">
            <img src="http://bootstraptema.ru/snippets/slider/2016/testimonials/testimonials-1.jpg" alt="">
          </div>
          <h3 class="testimonial-title"> Albus </h3>
          <small class="post"Web></small>
          <p class="description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
          </p>
        </div>






      </div>
      <!-- ./owl-carousel -->
    </div>
    <!-- ./col-md-offset-2 col-md-8 -->
  </div>
  <!-- ./row -->
</div>

</body>

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



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Owl Carousel прокрутку по n элементов даже если слайдов меньше n FirstFrost jQuery 12 09.01.2018 13:53
Создание, продвижение и оптимизация сайта Evgenij83 Работа 0 10.06.2017 17:23
Создание Конструктора sheckler Элементы интерфейса 1 25.05.2015 12:02
Создание своей библиотеки. Создание двух одинаковых объектов. Как избежать? IDCh Javascript под браузер 2 31.10.2012 12:53
Создание скрипта "Итеррационные циклы" по формуле krasopetka Общие вопросы Javascript 0 17.11.2011 12:42