這是一個起點。不要太花哨,可以改進。嘗試一下這裏:https://jsfiddle.net/MarkSchultheiss/odk9a9vv/注意我不是很瞭解enjin所以你必須努力,在
標記
<div class="dropdown">
<a class="greeting" href="#"><span class="name">My Account</span><span class="dropdownimage">▼</span></a>
<div class="submenu">
<ul class="root">
<li><a class="login" href="/login">Login</a></li>
<li><a class="profile" href="/profile">Profile</a></li>
</ul>
</div>
</div>
<div class="contentcontainer">
<div class="user">
<span class="element_username">I am Harry</span>
</div>
<div class="topHead_text">
Tophead Text
</div>
</div>
代碼
$(document).ready(function() {
var username = $('.user span.element_username').text();
if (!username) {
username = 'Hello Guest!';
$('.login').text("Login").attr('href', '/login');
$('.profile').text("Register").attr('href', '/login/do/register');
}
$(".greeting").data('ishidden', true).find('.name').text(username);
$(".greeting").on('click', function() {
var X = $(this).data('ishidden');
$(".submenu").toggle(X);
$(this).data('ishidden', !X);
});
//Mouse click on sub menu
$(".submenu").on('mouseup', function() {
return false;
});
//Mouse click on user link
$(".greeting").mouseup(function() {
return false;
});
//Document Click to hide menu
$(document).on('mouseup', function() {
$(".submenu").hide();
$(".greeting").data('isshown', '');
});
});
CSS:
.contentcontainer {
position: relative;
height: 2em;
top: 3em;
}
.dropdown {
top: 1em;
position: relative;
text-align: left;
font-family: arial;
font-weight: bold;
}
.dropdown * {
text-decoration: none;
font-size: 1em;
color: #000000;
}
.dropdownimage {
padding-right: 1em;
padding-left: 1em;
display: inline-block;
}
.submenu {
background: #ffffff;
position: absolute;
top: -0.75em;
left: -1em;
z-index: 100;
width: 10em;
display: none;
margin-left: 0.6em;
padding: 3em 0 0.25em;
border-radius: 6px;
box-shadow: 0 0.1em 0.8em rgba(0, 0, 0, 0.45);
}
.dropdown li a {
color: #000000;
display: block;
padding: 0.3em 1em;
cursor: pointer;
}
.dropdown li a:hover {
background: #155FB0;
color: #FFFFFF;
}
a.greeting {
background-color: #FFFFFF;
background-color: pink;
position: absolute;
z-index: 110;
display: block;
padding: 0.5em 0 0 0.75em;
height: 2em;
margin: -0.75em 0 0 -0.4em;
cursor: pointer;
}
.root {
list-style: none;
margin: 0;
padding: 0;
font-size: 1em;
padding: 0.5em 0 0 0;
border-top: 1px solid #dedede;
}
我真的很喜歡preciate幫助與此.. – Cmnd