javascript - Positioning a Dropdown Where Button Was Clicked -
i have alloy ui dropdown component want render when user clicks on 1 of 4 buttons - dropdown should positioned left of button clicked
var toolsdropdown = new y.dropdown({ boundingbox: '#my-div', trigger: '.option', hideonclickoutside: true, hideonesc: true }).render();
i dropdown menu render wherever position of button clicked (imagine these buttons displayed in each row of table)
<div id="my-div"> <div id="container-1"> <button id="options-btn-1" class="option" type="button">option one</button> </div> <div id="container-2"> <button id="options-btn-2" class="option" type="button">option two</button> </div> <div id="container-3"> <button id="options-btn-3" class="option" type="button">option three</button> </div> <div id="container-4"> <button id="options-btn-4" class="option" type="button">option four</button> </div> </div>
i have listener setup listen each button clicked
y.all('button.option-btn').on('click', displaydropdown);
however i'm having trouble getting function (maybe don't understand how alloy's dropdown works) - ideas?
edit: think might fair better yui's overlay widget
overlay positionable , stackable widget, provides support standard module format layout, header, body , footer section.
try this:
<head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> <link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" /> <script src="http://cdn.alloyui.com/2.0.0pr5/aui/aui-min.js"></script> <link href="http://cdn.alloyui.com/2.0.0pr5/aui-css/css/bootstrap.min.css" rel="stylesheet"> <style> </style> </head> <div id="my-div"> <div id="container-1"> <button id="options-btn-1" class="option" type="button">option one</button> </div> <div id="container-2"> <button id="options-btn-2" class="option" type="button">option two</button> </div> <div id="container-3"> <button id="options-btn-3" class="option" type="button">option three</button> </div> <div id="container-4"> <button id="options-btn-4" class="option" type="button">option four</button> </div> <button class="btn btn-primary" id="primary">primary</button> <div class="aui-dropdown" id="drp"> <a class="aui-dropdown-toggle" data-toggle="dropdown" href="#menu1"> dropdown <b class="aui-caret"></b> </a> <ul class="aui-dropdown-menu"> <li><a href="#">action</a></li> <li><a href="#">another action</a></li> <li><a href="#">something else here</a></li> <li class="aui-divider"></li> <li><a href="#">separated link</a></li> </ul> </div> </div> <script> $(document).ready(function(){ yui().use('node', 'node-focusmanager', function (y) { var document = y.one(document), toggler = y.one('.aui-dropdown-toggle'), dropdown = y.one('.aui-dropdown-menu'), buttonaction = y.one('#primary'), dropdowndiv = y.one('#drp'); buttonone=y.one("#options-btn-1"); buttontwo=y.one("#options-btn-2"); buttonaction.on('click', function(e) { dropdowndiv.setstyle('top','-20px'); dropdowndiv.setstyle('left','120px'); dropdown.toggleclass('aui-show'); e.preventdefault(); }); buttontwo.on('click', function(e) { dropdowndiv.setstyle('top','-125px'); dropdowndiv.setstyle('left','120px'); //dropdown.toggleclass('aui-show'); e.preventdefault(); }); buttonone.on('click', function(e) { dropdowndiv.setstyle('top','-145px'); dropdowndiv.setstyle('left','120px'); //dropdown.toggleclass('aui-show'); e.preventdefault(); }); toggler.on('click', function(e) { dropdown.toggleclass('aui-show'); e.preventdefault(); e.stoppropagation(); }); document.on('click', function() { dropdown.removeclass('aui-show'); }); }); }); </script> </body> </html>
Comments
Post a Comment