2016-08-31 7 views
0

Я создал скользящий контент, меню вверху, которое вы нажимаете, и содержимое ниже слайдов до следующего «li».скользящий div внутри другого slidng div

В последней ссылке в главном меню «сменные фильтры» есть еще один раздвижной контент внутри него.

, похоже, тормозит со второй системой, находящейся в первичной обмотке.

JS скрипку:

https://jsfiddle.net/ph3ng2fo/30/

Сценарий:

var isTabSelected = false; 
var lastSelectedTabLeftPos; 
$(".tab_item").mouseover(function() { 
      var $this = $(this); 
      $this.parent().find(".moving_bg").stop().animate({ 
       left: $this.position()['left'] 
      }, { duration: 300 }); 
    }); 
    $(".tab_item").mouseout(function() { 
    if(isTabSelected){ 

    $(".moving_bg").stop().animate({ 
       left: ""+lastSelectedTabLeftPos 
      }, { duration: 300 }); 
    }else 
    { 
    $(".moving_bg").stop().animate({ 
       left: "0" 
      }, { duration: 300 }); 
    } 
     }); 
$(".tab_item").click(function() { 
isTabSelected = true; 
var $this = $(this); 
lastSelectedTabLeftPos = $this.position()['left']; 
}); 


//Slide Content 
var TabbedContent = { 
    current: {i:null, obj:null}, 
    init: function() { 
     $(".tab_item").click(function() { 
       $(".tab_item").removeClass("tab_item_color"); 
    $(this).addClass("tab_item_color"); 
      var $this = $(this); 
      TabbedContent.slideContent($this); 
     }); 
     TabbedContent.current.i = 0; 
     TabbedContent.current.obj = $(".tabslider li").eq(0); 
    }, 
    slideContent: function($obj) { 
     var $container = $obj.closest(".tabbed_content"),   
      $contentContainer = $('.bodymainMaxS'), 
      $tabslider = $contentContainer.find(".tabslider"); 
     var i = $obj.index() - 1; 
     var $lis = $tabslider.find("li"); 
     $new = $lis.eq(i); 
     if(i === TabbedContent.current.i) { 
      return; 
     } 
     $lis.hide().filter($new.add(TabbedContent.current.obj)).show(); 
     var margin_1 = (i > TabbedContent.current.i) ? 0 : -$new.width(); 
     var margin_2 = (i < TabbedContent.current.i) ? 0 : -$new.width(); 
     $tabslider.stop().css({ 
      marginLeft: margin_1 + "px" 
     }).animate({ 
      marginLeft: margin_2 + "px" 
     }, 400); 
     TabbedContent.current.i = i; 
     TabbedContent.current.obj = $new; 
    } 
} 
TabbedContent.init(); 

var isTabSelected2 = false; 
var lastSelectedTabLeftPos2; 
$(".tab_item2").mouseover(function() { 
      var $this2 = $(this); 
      $this2.parent().find(".moving_bg2").stop().animate({ 
       top: $this2.position()['top'] 
      }, { duration: 300 }); 
    }); 
    $(".tab_item2").mouseout(function() { 
    if(isTabSelected2){ 

    $(".moving_bg2").stop().animate({ 
       top: ""+lastSelectedTabLeftPos2 
      }, { duration: 300 }); 
    }else 
    { 
    $(".moving_bg2").stop().animate({ 
       top: "0" 
      }, { duration: 300 }); 
    } 
     }); 
$(".tab_item2").click(function() { 
isTabSelected2 = true; 
var $this2 = $(this); 
lastSelectedTabLeftPos2 = $this2.position()['top']; 
}); 


var TabbedContent2 = { 
    current2: {i2:null, obj2:null}, 
    init: function() { 
      $(".tab_item2").click(function() { 
      $(".tab_item2").removeClass("tab_item_color2"); 
      $(this).addClass("tab_item_color2"); 
     var $this2 = $(this); 
     TabbedContent2.slideContent2($this2); 
     }); 
     TabbedContent2.current2.i2 = 0; 
     TabbedContent2.current2.obj2 = $(".tabslider2 li").eq(0); 
    }, 
    slideContent2: function($obj2) { 
     var $container2 = $obj2.closest(".tabbed_content2"),   
      $contentContainer2 = $('.slide_content2'), 
      $tabslider2 = $contentContainer2.find(".tabslider2"); 
     var i2 = $obj2.index() - 1; 
     var $lis2 = $tabslider2.find("li"); 
     $new2 = $lis2.eq(i2); 
     if(i2 === TabbedContent2.current2.i2) { 
      return; 
     } 
     $lis2.hide().filter($new2.add(TabbedContent2.current2.obj2)).show(); 
     var margin_1b = (i2 < TabbedContent2.current2.i2) ? 0 : -$new2.width(); 
     var margin_2b = (i2 > TabbedContent2.current2.i2) ? 0 : -$new2.width(); 
     $tabslider2.stop().css({ 
      marginLeft: margin_1b + "px" 
     }).animate({ 
      marginLeft: margin_2b + "px" 
     }, 400); 
     TabbedContent2.current2.i2 = i2; 
     TabbedContent2.current2.obj2 = $new2; 
    } 
} 
TabbedContent2.init(); 

Спасибо за вашу помощь

+0

Проверьте вашу скрипку, он, кажется, не работает для меня –

+0

Да, jQuerry не был загружен в тот скрипку. Загрузите его, и он начнет работать для элементов первого уровня. – shariqkhan

+0

См. Здесь http://stackoverflow.com/questions/38915965/slide-two-divs-simultaneous – Developer

ответ

0

Проблема с кодом является то, что эффект скольжения работает на элементы с классами .tab_item ',' .tabslide r 'и' .tabbed_content '

Элементы уровня 2 У этих классов нет этих классов. Вместо этого в их именах классов добавлено «2». Например, '.tab_item ', '.tabslider 'и' .tabbed_content '

Так что вам нужно: 1. Либо правильно имена классов 2-го уровня элементов путем удаления " 2 "от них. НО это также потребует внесения значительных изменений в объект TabbedContent и его функции, потому что теперь вам нужно будет провести различие между родителями уровня 1 «tab_item» и уровнем 2 «tab_item»

  1. Второй вариант заключается в том, чтобы сохранить имена классов вложенных (Уровень 2) элементов без изменений, т.е. прилагается к «2». Затем скопируйте объект TabbedContent и функцию и напишите еще одну функцию TabbedContent2, в которой вы заменяете «.tab_item» на «.tab_item2» и «.tabslider» на «.tabslider2» и т. Д., Чтобы адресовать детей второго уровня

В приведенном ниже фрагменте кода используется второй подход.

var isTabSelected = false; 
 
var lastSelectedTabLeftPos; 
 
//alert(0); 
 
$(".tab_item").mouseover(function() { 
 
\t \t \t var $this = $(this); 
 
      $this.parent().find(".moving_bg").stop().animate({ 
 
       left: $this.position()['left'] 
 
      }, { duration: 300 }); 
 
    }); 
 
\t 
 
jQuery(".tab_item").mouseout(function() { 
 
if(isTabSelected){ 
 

 
$(".moving_bg").stop().animate({ 
 
\t \t \t left: ""+lastSelectedTabLeftPos 
 
\t \t }, { duration: 300 }); 
 
}else 
 
{ 
 
$(".moving_bg").stop().animate({ 
 
\t \t \t left: "0" 
 
\t \t }, { duration: 300 }); 
 
} 
 
}); 
 

 
$(".tab_item").click(function() { 
 
isTabSelected = true; 
 
var $this = $(this); 
 
lastSelectedTabLeftPos = $this.position()['left']; 
 
}); 
 

 
//Slide Content 
 
var TabbedContent = { 
 
    current: {i:null, obj:null}, 
 
    init: function() { 
 
     $(".tab_item").click(function() { 
 
\t \t \t  $(".tab_item").removeClass("tab_item_color"); 
 
    $(this).addClass("tab_item_color"); 
 
      var $this = $(this); 
 
      TabbedContent.slideContent($this); 
 
     }); 
 
     TabbedContent.current.i = 0; 
 
     TabbedContent.current.obj = $(".tabslider li").eq(0); 
 
    }, 
 
    slideContent: function($obj) { 
 
     var $container = $obj.closest(".tabbed_content"),   
 
      $contentContainer = $('.bodymainMaxS'), 
 
     \t $tabslider = $contentContainer.find(".tabslider"); 
 
     var i = $obj.index() - 1; 
 
     var $lis = $tabslider.find("li"); 
 
     $new = $lis.eq(i); 
 
     if(i === TabbedContent.current.i) { 
 
      return; 
 
     } 
 
     $lis.hide().filter($new.add(TabbedContent.current.obj)).show(); 
 
     var margin_1 = (i > TabbedContent.current.i) ? 0 : -$new.width(); 
 
     var margin_2 = (i < TabbedContent.current.i) ? 0 : -$new.width(); 
 
     $tabslider.stop().css({ 
 
      marginLeft: margin_1 + "px" 
 
     }).animate({ 
 
      marginLeft: margin_2 + "px" 
 
     }, 400); 
 
     TabbedContent.current.i = i; 
 
     TabbedContent.current.obj = $new; 
 
    } 
 
}; 
 
TabbedContent.init(); 
 
var TabbedContent2 = { 
 
    current: {i:null, obj:null}, 
 
    init: function() { 
 
     $(".tab_item2").click(function() { 
 
\t \t \t  $(".tab_item2").removeClass("tab_item_color"); 
 
    $(this).addClass("tab_item_color"); 
 
      var $this = $(this); 
 
      TabbedContent2.slideContent($this); 
 
     }); 
 
     TabbedContent2.current.i = 0; 
 
     TabbedContent2.current.obj = $(".tabslider2 li").eq(0); 
 
    }, 
 
    slideContent: function($obj) { 
 
     var $container = $obj.closest(".tabbed_content2"),   
 
      $contentContainer = $('.bodymainMaxS'), 
 
     \t $tabslider = $contentContainer.find(".tabslider2"); 
 
     var i = $obj.index() - 1; 
 
     var $lis = $tabslider.find("li"); 
 
     $new = $lis.eq(i); 
 
     if(i === TabbedContent2.current.i) { 
 
      return; 
 
     } 
 
     $lis.hide().filter($new.add(TabbedContent2.current.obj)).show(); 
 
     var margin_1 = (i > TabbedContent2.current.i) ? 0 : -$new.width(); 
 
     var margin_2 = (i < TabbedContent2.current.i) ? 0 : -$new.width(); 
 
     $tabslider.stop().css({ 
 
      marginLeft: margin_1 + "px" 
 
     }).animate({ 
 
      marginLeft: margin_2 + "px" 
 
     }, 400); 
 
     TabbedContent2.current.i = i; 
 
     TabbedContent2.current.obj = $new; 
 
    } 
 
}; 
 
TabbedContent2.init();
.tabbed_content { 
 
    background-color: #000; 
 
    width: 100%; 
 
    overflow: hidden; 
 
    position: relative; 
 
    width: 100%; 
 
    height: 100%; 
 
    margin-left: 10px; 
 
} 
 

 
.tabs { 
 
    position: relative; 
 
\t width:70%; 
 
\t float:left;} 
 

 
.tabs .moving_bg { 
 
    background-color:#000; 
 
    background-image:url(/images/arrow_down_blue.png); 
 
    position: absolute; 
 
    width: 600px; 
 
    z-index: 7; 
 
    left: 0; 
 
    padding-bottom: 19px; 
 
    background-position: left bottom; 
 
    background-repeat: no-repeat; 
 
\t margin: 0 auto; 
 

 
} 
 

 
.tab_item { 
 
    display: block; 
 
    float: left; 
 
    width: 150px; 
 
    color: #bbb; 
 
    text-align: center; 
 
    z-index: 8; 
 
    position: relative; 
 
    cursor: pointer; 
 
\t font-family: 'SourceSansPro-SemiBold'; 
 
\t font-size: 15px; 
 
\t border-left: 1px solid #333; 
 
\t padding: 8px 10px 8px 10px; 
 
\t margin: 0 auto; 
 
\t text-align:center; \t 
 

 
} 
 
.tab_item:hover { 
 
\t color: #fff; 
 
\t \t border-left: 1px solid #333; 
 

 
} 
 

 
.tab_item_color { 
 
\t \t color: #fff; 
 
} 
 

 
.slide_content { 
 
\t width:1100px; 
 
\t overflow:hidden; 
 
\t margin: 26px 10px 0 5px; 
 
} 
 
.tabslider { 
 
    width: 6000px; 
 
    color: #222; 
 
} 
 
.tabslider ul { 
 
\t list-style:none; 
 
\t width:1100px; 
 
} 
 

 
.tabslider li /*media adjust */ { 
 
\t list-style:none; 
 
    float: left; 
 
    width: 1090px; 
 
    text-align: justify; 
 
    padding:0 10px 0 0; 
 
} 
 

 
.tabslider ul a { 
 
    color: #222; 
 
    text-decoration: none; 
 

 
} 
 
.tabslider ul a:hover { 
 
    color: #222; 
 
} 
 
.tabslider ul li { 
 
    padding-bottom: 7px; 
 
} 
 

 

 
.tabbed_content2 { 
 
    background-color: #fff; 
 
    width: 150px; 
 
    overflow: hidden; 
 
    position: relative; 
 
    height: 100%; 
 
    margin-left: 10px; 
 
    float:left; 
 
} 
 

 
.tabs2 { 
 
    position: relative; 
 
\t width:20%; 
 

 
} 
 

 
.tabs2 .moving_bg2 { 
 
    background-color:; 
 
    background-image:url(/images/arrow_down_blue.png); 
 
    position: absolute; 
 
    width: 150px; 
 
    z-index: 7; 
 
    left: 0; 
 
    padding-bottom: 19px; 
 
    background-position: left bottom; 
 
    background-repeat: no-repeat; 
 
\t margin: 0 auto; 
 

 
} 
 

 
.tab_item2 { 
 
    display: block; 
 
    float: left; 
 
    width: 150px; 
 
    color: #bbb; 
 
    text-align: center; 
 
    z-index: 8; 
 
    position: relative; 
 
    cursor: pointer; 
 
\t font-family: 'SourceSansPro-SemiBold'; 
 
\t font-size: 15px; 
 
\t padding: 8px 10px 8px 10px; 
 
\t margin: 0 auto; 
 
\t text-align:center; \t 
 
} 
 
.tab_item2:hover { 
 
\t color: #333; 
 

 
} 
 

 
.tab_item_color2 { 
 
\t \t color: #333; 
 
} 
 

 
.slide_content2 { 
 
\t width:910px; 
 
\t overflow:hidden; 
 
\t margin: 26px 10px 0 5px; 
 
float:left; 
 
} 
 
.tabslider2 { 
 
    width: 6000px; 
 
    color: #222; 
 
} 
 
.tabslider2 ul { 
 
\t list-style:none; 
 
\t width:910px; 
 
} 
 

 
.tabslider2 li /*media adjust */ { 
 
\t list-style:none; 
 
    float: left; 
 
    width: 900px; 
 
    text-align: justify; 
 
    padding:0 10px 0 0; 
 
} 
 

 
.tabslider2 ul a { 
 
    color: #222; 
 
    text-decoration: none; 
 

 
} 
 
.tabslider2 ul a:hover { 
 
    color: #222; 
 
} 
 
.tabslider2 ul li { 
 
    padding-bottom: 7px; 
 
} 
 

 

 
.bodymainMax { 
 
\t width: 100%; 
 
\t background: none; 
 
\t overflow: visible; 
 
\t clear:both; 
 
\t margin: 0 auto; 
 
\t padding: 0 0 0 0; 
 
} 
 
.bodymainMaxS { 
 
\t width: 100%; 
 
\t background: none; 
 
\t overflow: visible; 
 
\t clear:both; 
 
\t margin: 0 auto; 
 
\t padding: 0 0 0 0; 
 
} 
 
.bblock1 { 
 
\t width: 100%; 
 
\t background: #000; 
 
\t clear:both; 
 
} 
 

 
.bblock3body { 
 
\t width: 100%; 
 
\t background: #ccc; 
 
\t padding: 10px 0 10px 0; 
 
\t clear:both; 
 
} 
 

 
.bblock1 { 
 
\t width: 100%; 
 
\t background: #000; 
 
\t clear:both; 
 
} 
 

 
.bblock2 { 
 
\t width: 100%; 
 
\t background: #217DD1; 
 
\t clear:both; 
 
\t min-height:3px; 
 
} 
 

 
.bblock3 { 
 
\t width: 100%; 
 
\t background: #ccc; 
 
\t padding: 10px 0 10px 0; 
 
\t clear:both; 
 
} 
 
.container { 
 
\t width: 1130px; 
 
\t margin: 0 auto; 
 
\t vertical-align: middle; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="bblock1"> 
 
<div class="container"> 
 
<div class="bodymainMaxS"> 
 
\t <div class='tabbed_content'> 
 
\t  <div class='tabs'> 
 
\t   <div class='moving_bg'>&nbsp;</div> 
 
\t   <span class='tab_item tab_item_color'>OVERVIEW</span> 
 
\t   <span class='tab_item'>THE SCIENCE</span> 
 
\t   <span class='tab_item'>ORDER</span> 
 
\t   <span class='tab_item'>REPLACEMENT FILTERS</span> 
 
\t  </div> 
 
\t </div> 
 
</div> 
 
</div> 
 
</div> 
 
<div class="bblock3"> 
 
<div class="container"> 
 
<div class="bodymainMaxS"> 
 
\t  <div class='slide_content'>       
 
\t   <ul class='tabslider'> 
 
<!--1st SLIDE --> 
 
\t \t \t \t <li> 
 
\t \t \t \t \t yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 
 
\t \t \t \t \t 
 
\t \t \t \t </li> 
 
<!--2nd SLIDE --> 
 
\t \t \t \t <li> 
 
\t \t \t \t kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk 
 
\t \t \t \t </li> 
 
<!--3rd SLIDE --> 
 
\t \t \t \t <li> 
 
\t \t \t \t uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu 
 
\t \t \t \t </li> 
 
<!--4th SLIDE --> 
 
\t \t \t \t <li> 
 
\t \t \t \t <div class='tabbed_content2'> 
 
\t \t \t \t \t <div class='tabs'> 
 
\t \t \t \t \t \t <div class='moving_bg2'>&nbsp;</div> 
 
\t \t \t \t \t \t <span class='tab_item2 tab_item_color2'>OVERVIEW</span> 
 
\t \t \t \t \t \t <span class='tab_item2'>THE SCIENCE</span> 
 
\t \t \t \t \t \t <span class='tab_item2'>ORDER</span> 
 
\t \t \t \t \t \t <span class='tab_item2'>REPLACEMENT FILTERS</span> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t <div class='slide_content2'>       
 
\t \t \t \t \t <ul class='tabslider2'> 
 
\t \t \t \t \t \t <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed doeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quisUt enimad minim veniam, quis nostrud exercitation ullamc</li> 
 
\t \t \t \t \t \t <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed doeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi utaliquip ex ea commodo consequat. Duis aute irure dolor inreprere magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamc</li> 
 
\t \t \t \t \t \t <li>Lorem ipsum dolor sidunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamc</li> 
 
\t \t \t \t \t \t <li>Lorem ipsum olore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamc</li> 
 
\t \t \t \t \t </ul> 
 
\t \t \t \t </div> 
 
\t \t \t \t </li> 
 
\t \t \t </ul> 
 
\t \t </div> 
 
</div> 
 
</div> 
 
</div>

+0

Невозможно заставить скрипту работать на всех моих работах, кроме прокрутки на втором скользящем div, работает неправильно. основной делает. – alwayslearning

+0

Я чувствую, что уже сделал то, что вы предложили, переименовав элементы с помощью «2», у css js и html все есть новые имена. но все равно не скользит правильно. разочарование, что я не могу заставить его работать вообще со скрипкой, чтобы вы могли видеть. https: // jsfiddle.net/ph3ng2fo/29/updated – alwayslearning

+0

@david Я вижу прокрутку, работающую на уровне 1, а также элементы уровня 2 в вашем jsfiddle https://jsfiddle.net/ph3ng2fo/29/ Что не работает для вас? – shariqkhan

Смежные вопросы