[英]Single Button with Drop Down Menu Effects - Help Refine
我在一个客户网站上工作,他们希望网站的主横幅上有一个下拉按钮。
我能够对其进行编码并使其正常工作,但似乎有点气质。 该按钮有效,但并非每次都单击该按钮,并且一定不会平稳。 有人可以看一下,让我知道他们是否与该代码有其他冲突,或者我可以做些什么来对其进行微调并使其更好地工作?
我正在使用以下CSS:
/* Dropdown Button */
.dropbtn {
background-color: rgba(102, 146, 255, 0.87);
color: white;
padding: 9px 15px 14px 15px;
font-size: 16px;
border: none;
cursor: pointer;
border-radius: 6px;
}
/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: #6692FF;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 9px 32px;
text-decoration: none;
display: block !important;
border-bottom: 1px solid #4A5056;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f9f9f9}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}
以下HTML:
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn"><span style=" vertical-align: bottom;font-size: 24px; ">LISTEN</span> <i class="fa fa-volume-up fa-4x"></i></button>
<div id="myDropdown" class="dropdown-content">
<a href="http://lonebeacondevelopment.com/financialexchange/listen-live/" class="popup" data-height="300" data-width="300" data-scrollbars="0" alt="LISTEN LIVE">
LISTEN LIVE</a>
<a href="http://lonebeacondevelopment.com/financialexchange/on-demand/">ON DEMAND</a>
</div>
</div>
和下面的JS:
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
链接为http://lonebeacondevelopment.com/financialexchange/,是横幅右上角的蓝色“收听”按钮。
任何帮助将不胜感激。
非常感谢!
好的,您可以做的是在按钮内部移除跨度,然后在按钮类中粘贴跨度样式
的CSS
/* Dropdown Button */
.dropbtn {
background-color: rgba(102, 146, 255, 0.87);
color: white;
padding: 9px 15px 14px 15px;
font-size: 16px;
border: none;
cursor: pointer;
border-radius: 6px;
vertical-align: bottom;font-size: 24px; /*HERE The CODE of SPAN*/
}
/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: #6692FF;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 9px 32px;
text-decoration: none;
display: block !important;
border-bottom: 1px solid #4A5056;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f9f9f9}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}
的HTML
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">LISTEN <i class="fa fa-volume-up fa-4x"></i></button>
<div id="myDropdown" class="dropdown-content">
<a href="http://lonebeacondevelopment.com/financialexchange/listen-live/" class="popup" data-height="300" data-width="300" data-scrollbars="0" alt="LISTEN LIVE">
LISTEN LIVE</a>
<a href="http://lonebeacondevelopment.com/financialexchange/on-demand/">ON DEMAND</a>
</div>
</div>
您只需为按钮设置函数“ myFunction”,但这并不意味着它将由按钮内的span或i元素触发。
要解决它,请尝试使用jQuery(使用jQuery):
的HTML
<div class="dropdown">
<div class="dropbtn"> <!--CHANGED THIS-->
<span style="vertical-align: bottom;font-size: 24px; ">LISTEN</span>
<i class="fa fa-volume-up fa-4x"></i>
</div>
<div id="myDropdown" class="dropdown-content">
<a href="http://lonebeacondevelopment.com/financialexchange/listen-live/" class="popup" data-height="300" data-width="300" data-scrollbars="0" alt="LISTEN LIVE">LISTEN LIVE</a>
<a href="http://lonebeacondevelopment.com/financialexchange/on-demand/">ON DEMAND</a>
</div>
</div>
JS / JQ
$( document ).ready(function() {
$(".dropbtn").click(function(){
document.getElementById("myDropdown").classList.toggle("show");
});
$("body").click(function(e){
if(e.target.className !== "form_wrapper"){
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.