手风琴走得太远

时间:2018-07-24 10:54:12

标签: jquery html css accordion

简介
通常我会尝试自己解决代码中的问题,但是有了这个,我需要您的帮助。我想说的是,我尝试了所有看似相似的解决方案,但是我不是非常有经验的编码人员,所以失败了。

因此,我有一个自定义手风琴的自定义代码,该代码显示了该手风琴风格的移动用户的网站/产品信息。您可以看到外观here,并且代码在这里:

( function( $ ) {
$( document ).ready(function() {
$('#cssmenu li.has-sub>a').on('click', function(){
		$(this).removeAttr('href');
		var element = $(this).parent('li');
		if (element.hasClass('open')) {
			element.removeClass('open');
			element.find('li').removeClass('open');
			element.find('ul').slideUp();
		}
		else {
			element.addClass('open');
			element.children('ul').slideDown();
			element.siblings('li').children('ul').slideUp();
			element.siblings('li').removeClass('open');
			element.siblings('li').find('li').removeClass('open');
			element.siblings('li').find('ul').slideUp();
		}
	});

	$('#cssmenu>ul>li.has-sub>a').append('<span class="holder"></span>');

	(function getColor() {
		var r, g, b;
		var textColor = $('#cssmenu').css('color');
		textColor = textColor.slice(4);
		r = textColor.slice(0, textColor.indexOf(','));
		textColor = textColor.slice(textColor.indexOf(' ') + 1);
		g = textColor.slice(0, textColor.indexOf(','));
		textColor = textColor.slice(textColor.indexOf(' ') + 1);
		b = textColor.slice(0, textColor.indexOf(')'));
		var l = rgbToHsl(r, g, b);
		if (l > 0.7) {
			$('#cssmenu>ul>li>a').css('text-shadow', '0 1px 1px rgba(0, 0, 0, .35)');
			$('#cssmenu>ul>li>a>span').css('border-color', 'rgba(0, 0, 0, .35)');
		}
		else
		{
			$('#cssmenu>ul>li>a').css('text-shadow', '0 1px 0 rgba(255, 255, 255, .35)');
			$('#cssmenu>ul>li>a>span').css('border-color', 'rgba(255, 255, 255, .35)');
		}
	})();

	function rgbToHsl(r, g, b) {
	    r /= 255, g /= 255, b /= 255;
	    var max = Math.max(r, g, b), min = Math.min(r, g, b);
	    var h, s, l = (max + min) / 2;

	    if(max == min){
	        h = s = 0;
	    }
	    else {
	        var d = max - min;
	        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
	        switch(max){
	            case r: h = (g - b) / d + (g < b ? 6 : 0); break;
	            case g: h = (b - r) / d + 2; break;
	            case b: h = (r - g) / d + 4; break;
	        }
	        h /= 6;
	    }
	    return l;
	}
});
} )( jQuery );
#cssmenu,
#cssmenu ul,
#cssmenu ul li,
#cssmenu ul li a {
  margin: 0;
  padding: 0;
  border: 0;
  list-style: none;
  line-height: 1;
  display: block;
  position: relative;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

#cssmenu ul {/*Recheck, added fast!!!*/
    color: black;
    font-size: 12px;
    line-height: 18px;
}
#cssmenu {
  width: 100%;
  font-family: Helvetica, Arial, sans-serif;
  color: #ffffff;
}
#cssmenu ul ul {
  display: none;
}
.align-right {
  float: right;
}
#cssmenu > ul > li > a {
  padding: 15px 20px;
  border-left: 1px solid #0f1632;
  border-right: 1px solid #0f1632;
  border-top: 1px solid #0f1632;
  cursor: pointer;
  z-index: 2;
  font-size: 14px;
  font-weight: bold;
  text-decoration: none;
  color: #ffffff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  background: #36aae7;
  background: -webkit-linear-gradient(#36aae7, #1fa0e4);
  background: -moz-linear-gradient(#36aae7, #1fa0e4);
  background: -o-linear-gradient(#36aae7, #1fa0e4);
  background: -ms-linear-gradient(#36aae7, #1fa0e4);
  background: linear-gradient(#36aae7, #1fa0e4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

#cssmenu > ul > li > a:hover,
#cssmenu > ul > li.active > a,
#cssmenu > ul > li.open > a {
  color: #eeeeee;
  background: #0f1632 !important;
  background: -webkit-linear-gradient(#1fa0e4, #1992d1);
  background: -moz-linear-gradient(#1fa0e4, #1992d1);
  background: -o-linear-gradient(#1fa0e4, #1992d1);
  background: -ms-linear-gradient(#1fa0e4, #1992d1);
  background: linear-gradient(#1fa0e4, #1992d1);
}

#cssmenu > ul > li.open > a {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid #0f1632;
}

#cssmenu > ul > li:last-child > a,
#cssmenu > ul > li.last > a {
  border-bottom: 1px solid #0f1632;
}
.holder {
  width: 0;
  height: 0;
  position: absolute;
  top: 0;
  right: 0;
}

.holder::after,
.holder::before {
  display: block;
  position: absolute;
  content: "";
  width: 6px;
  height: 6px;
  right: 20px;
  z-index: 10;
  -webkit-transform: rotate(-135deg);
  -moz-transform: rotate(-135deg);
  -ms-transform: rotate(-135deg);
  -o-transform: rotate(-135deg);
  transform: rotate(-135deg);
}
.holder::after {
  top: 17px;
  border-top: 2px solid #ffffff;
  border-left: 2px solid #ffffff;
}

#cssmenu > ul > li > a:hover > span::after,
#cssmenu > ul > li.active > a > span::after,
#cssmenu > ul > li.open > a > span::after {
  border-color: #eeeeee;
}
.holder::before {
  top: 18px;
  border-top: 2px solid;
  border-left: 2px solid;
  border-top-color: inherit;
  border-left-color: inherit;
}
#cssmenu ul ul li a {
  cursor: pointer;
  border-bottom: 1px solid #32373e;
  border-left: 1px solid #32373e;
  border-right: 1px solid #32373e;
  padding: 10px 20px;
  z-index: 1;
  text-decoration: none;
  font-size: 13px;
  color: #eeeeee;
  background: #49505a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#cssmenu ul ul li:hover > a,
#cssmenu ul ul li.open > a,
#cssmenu ul ul li.active > a {
  background: #0f1632;
  color: #ffffff;
}
#cssmenu ul ul li:first-child > a {
  box-shadow: none;
}
#cssmenu ul ul ul li:first-child > a {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
#cssmenu ul ul ul li a {
  padding-left: 30px;
}
#cssmenu > ul > li > ul > li:last-child > a,
#cssmenu > ul > li > ul > li.last > a {
  border-bottom: 0;
}
#cssmenu > ul > li > ul > li.open:last-child > a,
#cssmenu > ul > li > ul > li.last.open > a {
  border-bottom: 1px solid #32373e;
}
#cssmenu > ul > li > ul > li.open:last-child > ul > li:last-child > a {
  border-bottom: 0;
}
#cssmenu ul ul li.has-sub > a::after {
  display: block;
  position: absolute;
  content: "";
  width: 5px;
  height: 5px;
  right: 20px;
  z-index: 10;
  top: 11.5px;
  border-top: 2px solid #eeeeee;
  border-left: 2px solid #eeeeee;
  -webkit-transform: rotate(-135deg);
  -moz-transform: rotate(-135deg);
  -ms-transform: rotate(-135deg);
  -o-transform: rotate(-135deg);
  transform: rotate(-135deg);
}
#cssmenu ul ul li.active > a::after,
#cssmenu ul ul li.open > a::after,
#cssmenu ul ul li > a:hover::after {
  border-color: #ffffff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cssmenu">

<ul>
  <li class="active has-sub"><a href="#"><span>Par Klīniku</span></a>
  <ul>
    <li class="has-sub"><a href="#"><span>Par Klīniku</span></a>
  <ul>
   <li>[contentblock id=6]</li>
</ul>
</li>
</ul>


<ul>
<li class="has-sub"><a href="#"><span>Mūsu komanda</span></a>
<ul>
<li style="height: 900px;">[contentblock id=8]</li>
</ul>
</li>
</ul>
</li>

<li class="active has-sub"><a href="#"><span>Ginekoloģija</span></a>
<ul>
<li class="has-sub"><a href="#"><span>Konsultācija</span></a>
<ul>
<li>[contentblock id=9]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Ginekoloģiskā ultrasonogrāfija</span></a>
<ul>
<li>[contentblock id=10]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Ginekoloģiskās operācijas</span></a>
<ul>
<li>[contentblock id=11]</li>
</ul>
</li>
</ul>
</li>


<li class="active has-sub"><a href="#"><span>Grūtnieču novērošana</span></a>
<ul>
<li>[contentblock id=12]</li>
</ul>
</li>





<li class="active has-sub"><a href="#"><span>Ginekoloģiskās saslimšanas</span></a>
<ul>
<li class="has-sub"><a href="#"><span>Olnīcu cista</span></a>
<ul>
<li>[contentblock id=13]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Olnīcu vēzis</span></a>
<ul>
<li>[contentblock id=14]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Dzemdes vēzis</span></a>
<ul>
<li>[contentblock id=15]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Dzemdes kakla vēzis</span></a>
<ul>
<li>[contentblock id=16]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Vulvas vēzis</span></a>
<ul>
<li>[contentblock id=17]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Ģenētiskās analīzes</span></a>
<ul>
<li>[contentblock id=18]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Dzemdes mioma</span></a>
<ul>
<li>[contentblock id=19]</li>
</ul>
</li>
</ul>
</li>
<li class="active has-sub"><a href="#"><span>Krūts veselība</span></a>
<ul>
<li class="has-sub"><a href="#"><span>Krūts pārbaudes</span></a>
<ul>
<li>[contentblock id=20]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Krūts ķirurģija</span></a>
<ul>
<li>[contentblock id=21]</li>
</ul>
</li>
</ul>
</li>
<li class="active has-sub"><a href="#"><span>Ķirurģija</span></a>
<ul>
<li class="has-sub"><a href="#"><span>Kuņģa vēzis</span></a>
<ul>
<li>[contentblock id=22]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Žultsakmeņu slimība</span></a>
<ul>
<li>[contentblock id=23]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Resnās zarnas vēzis</span></a>
<ul>
<li>[contentblock id=24]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Ādas veidojumi</span></a>
<ul>
<li>[contentblock id=25]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Dzimumzīmes</span></a>
<ul>
<li>[contentblock id=26]</li>
</ul>
</li>
</ul>
<ul>
<li class="has-sub"><a href="#"><span>Lipoma</span></a>
<ul>
<li>[contentblock id=27]</li>
</ul>
</li>
</ul>
</li>
<li class="active has-sub"><a href="#"><span>Cenrādis</span></a>
<ul>
<li>[contentblock id=28]</li>
</ul>
</li>


<li class="active has-sub"><a href="#"><span>Kontakti</span></a>
<ul>
<li>[contentblock id=29]</li>
</ul>
</li>
<li class="active has-sub"><a href="#"><span>Privātuma politika</span></a>
<ul>
<li>[contentblock id=privatuma]</li>
</ul>
</li>
<li class="active has-sub"><a href="#"><span>Dzīve pēc vēža</span></a>
<ul>
<li>[contentblock id=dzive-pec-veza]</li>
</ul>
</li>
</div>

<div style="background-color: pink; height: 1000px;">
</div>

问题/问题

它是多层(嵌套)手风琴,每个手风琴盒包含很多文本。此手风琴下还有其他包含内容的div。问题是,如果查看者从一个手风琴盒中读取内容,然后想打开另一个手风琴盒,则会在页面中将所有内容滚动太远。我想澄清一下-手风琴本身能很好地工作-主要问题-它使查看者在页面中走得太远了,但是我需要他看到他在页面顶部单击的元素。

示例

  1. 您点击:“ Par Kliniku”-“ Par Kliniku”和“MūsuKomanda”出现
  2. 您选择:“MŪsuKomanda”-向下滚动并看到“ Ginekologija”
  3. 您单击“ Ginekologija”,所有操作都将结束。这是我的问题。

0 个答案:

没有答案