Custom Dropdown
How do I make an custom dropdown?
What is a custom dropdown? How do you make a custom dropdown? This script and codes were developed by Tim on 31 October 2022, Monday.
Custom Dropdown - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Custom Dropdown</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<table> <tr> <td>Row 1</td> </tr> <tr> <td> <div id="dd"></div> </td> </tr> <tr> <td>Row 3</td> </tr>
</table> <script src="js/index.js"></script>
</body>
</html>
Custom Dropdown - Script Codes CSS Codes
tbody tr:nth-child(odd){ background-color: #ccc;
}
.dropdown{ cursor: default; -webkit-user-select: none;
}
.selectable:after{ position: relative; top: 10px; margin-left: 4px; content: ''; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 5px solid black;
}
.options ul{ list-style: none; margin: 0; padding: 0;
}
.options ul li:hover{ color:white;
}
.options ul li:nth-child(2){ background-color: green; border-radius: 12px; text-align: center;
}
.options ul li:nth-child(1){ background-color: red; border-radius: 12px; text-align: center;
}
.options ul li:nth-child(3){ background-color: blue; border-radius: 12px; text-align: center;
}
Custom Dropdown - Script Codes JS Codes
(function(){ var DropDown = function(el, arg_opts){ dropdown = {} dropdown.dd = document.getElementById(el) dropdown.opts = [] initEvents(dropdown, arg_opts) } let toggle = function(el){ el.style.display = (el.style.display === 'none') ? 'block' : 'none' } let hide = function(el){ el.style.display = 'none' } let initEvents = function(obj, arg_opts){ obj.dd.setAttribute('class','dropdown') //Generate selectable let selectable = document.createElement('div') selectable.setAttribute('class','selectable') selectable.textContent = 'Selectable' obj.dd.appendChild(selectable) obj.selectable = selectable //Generate options let options = document.createElement('div') let list = document.createElement('ul') for(text of arg_opts){ let opt = document.createElement('li') opt.textContent = text list.appendChild(opt) obj.opts.push(opt) } options.appendChild(list) options.setAttribute('class','options') obj.dd.appendChild(options) hide(options) obj.options = options obj.dd.addEventListener('click', function(e){ toggle(obj.options) obj.options.focus() }) for(o of obj.opts){ o.addEventListener('click',function(e){ obj.selectable.textContent = e.target.textContent }) } } let root = this root.DropDown = DropDown
})()
DropDown('dd',['red','green','blue'])
Developer | Tim |
Username | maytim |
Uploaded | October 31, 2022 |
Rating | 3 |
Size | 2,387 Kb |
Views | 16,192 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
IPhone Doodle | 1,994 Kb |
CSS Grid Calendar | 2,694 Kb |
Pixel paint | 3,468 Kb |
Game idea | 2,839 Kb |
Double Helix Animation - Jade and Sass | 2,497 Kb |
Pixi JS | 2,710 Kb |
Custom Multi Column Data Entry Select | 3,313 Kb |
Barbell | 5,192 Kb |
Bot Land Rankings | 3,592 Kb |
Double Helix Animation - Jade and Sass | 2,437 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
P1 | Vivi_Lai | 1,533 Kb |
A Pen by Jess | Jessamyne | 5,100 Kb |
LDE old privacy page | Jasonangle | 2,339 Kb |
UI Challenge - Budget Selector | AgentRR007 | 3,547 Kb |
Subtle site navigation with description | Necks | 3,206 Kb |
A Pen by Rob Levin | Roblevin | 2,787 Kb |
Basic jQuery Filter list | Mtedwards | 2,464 Kb |
Perspective Origin Demo | Agelber | 3,614 Kb |
Wikipedia Viewer | Thalpha | 4,426 Kb |
Awesome | Samarthpd | 2,901 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!