I am trying generating a dynamic bootstrap 3 dropdown menu for sharing on mouse hover.
See this picture
Instead of creating lots of HTML code I decided to generate dynamic menu. Here is what I have done so far:
<div class="dropdown dropup" >
<a href="#" class="open-dropdown" data-link="http://google.com">Dropdown</a>
<ul class="dropdown-menu" role="menu">
<li id="link1">Link One</li>
<li id="link2">Link Two</li>
<li class="caret"></li>
</ul>
</div>
$(function() {
$('.open-dropdown').hover(function(){
$('#link1').html("Share link 1 "+$(this).data('link'));
$('#link2').html("Share link 2 "+$(this).data('link'));
$('.open-dropdown').dropdown();
});
});
<ul class="dropdown-menu" role="menu">
code outside of <div class="dropdown dropup">
container. See this jsfiddle http://jsfiddle.net/LTk3x/ What about just using some CSS ? :)
.dropdown:hover .dropdown-menu{
display: block;
}
Here is a jsFiddle:
http://jsfiddle.net/hMp2r/
You can change $('.open-dropdown').dropdown();
by $('.dropdown-menu').toggle();
$(function() {
$('.open-dropdown').hover(function(){
$('#link1').html("Share link 1 "+$(this).data('link'));
$('#link2').html("Share link 2 "+$(this).data('link'));
$('.dropdown-menu').toggle();
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.