If you joined Digg, certainly you had known about the multi-topic navigation menu for choosing of this website, a navigation selection is quite simple but very effective. This type of navigation menu is created by a combination of CSS, JavaScript and HTML and this JavaScript tutorial will guide you how to create one like Digg style without using any JavaScript framework.
- Demo
- Enlarge
- Reload
- New window
Generate your business videos by AI with voice or just text
Your first FREE AI Video App! Automate Your First AI Video. Create Your Professional Video In 5 Minutes By AI No Equipment Or Video Editing Skill Requred. Effortless Video Production For Content Marketers.
To note here is the inclusion of the "digg_selector.js" file which we will look at next. Also important is the hidden field with the id of "hidden_data". Since what we're doing is replacing the functionality of radio buttons with nicely styled links, we need another way to get the information submitted and we do that with the hidden field. That's where the Javascript file comes in:
window.onload=function() { var container = document.getElementById('container'); var containerAnchors = container.getElementsByTagName('a'); // get anchors for(var j=0;j<containerAnchors.length;j++) { containerAnchors[j].onclick = handleClick; } }; function handleClick() { document.getElementById('hidden_data').value = this.id; var container = document.getElementById('container'); var containerAnchors = container.getElementsByTagName('a'); // unhighlight all the links for(var j=0;j++;containerAnchors.length;j++) { containerAnchors[j].style.backgroundColor = "#eceff6"; containerAnchors[j].style.color = "#3b5998"; } // highlight the link that was just clicked this.style.backgroundColor = "#3b5998"; this.style.color = "#ffffff"; }
This is simple - there are just 2 functions. Looking at the first one:
window.onload=function() { var container = document.getElementById('container'); var containerAnchors = container.getElementsByTagName('a'); // get anchors for(var j=0;j<containerAnchors.length;j++) { containerAnchors[j].onclick = handleClick; } };
When the page is loaded, we get all the anchors in the container div (these anchors are the digg style selectors/buttons or whatever you want to call them). Then, inside the for loop we attach an event handler to each anchor, which executes when the anchor is clicked. The event handler is a function called handleClick(), which we look at now:
function handleClick() { document.getElementById('hidden_data').value = this.id; var container = document.getElementById('container'); var containerAnchors = container.getElementsByTagName('a'); // unhighlight all the links for(var j=0;j<containerAnchors.length;j++) { containerAnchors[j].style.backgroundColor = "#eceff6"; containerAnchors[j].style.color = "#3b5998"; } // highlight the link that was just clicked this.style.backgroundColor = "#3b5998"; this.style.color = "#ffffff"; }
The line document.getElementById('hidden_data').value = this.id; gets a hold of the hidden field we talked about earlier, and dynamically sets its value to this.id . So what is this.id? Well, this refers to the anchor that gets clicked on. So this.id gets the id of the anchor. The hidden field is set, and when the form is submitted we can get the value of the hidden field in the $_POST['hidden_data'], assuming you're using PHP.
Finally, here's the CSS stylesheet, which needs to explanation:
body { font-family: "lucida grande", tahoma, verdana, arial, sans-serif; font-size: 15px; } a:link {color: #3b5998} a:visited {color: #3b5998} a:hover {color: #3b5998} a:active {color: #3b5998} h1 { font-family: Georgia, serif; font-style: italic; font-size: 20px; font-weight: bold; } hr { color: #A8A8A8; height: 1px; } #container { margin:0; margin-top: 20px; margin-bottom: 20px; } .digg_style_link { color: #3b5998; padding: 3px; margin: 3px; margin-bottom: 20px; background-color: #eceff6; text-decoration: none; border: 1px solid #d4dae8; }
That's pretty much all there is to it.
Source : http://localhost/topic-selectors-digg-style.html
- Sent (0)
- New
Generate your business videos by AI with voice or just text
chatGPTaz.com
Talk to ChatGPT by your mother language
AppAIVideo
Your first FREE AI Video App
Deepfake Video
Deepfake AI Video Maker
Deepfake
Deepfake AI Video Maker
AI Deep Fake
Deepfake AI Video Maker
AIvidio
AI Video Mobile Solutions
AIvideos
AI Video Platform & Solutions
AIvedio
AI Video App Maker
Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)
Artificial General Intelligence
Ai and higher level Artificial General Intelligence (AGI)
Faceswap AI Online
Swap Faces Video, Photo & GIFs Instantly with Powerful AI Tools - Faceswap AI Online FREE
Faceswap AI Online
Swap Faces Video, Photo & GIFs Instantly with Powerful AI Tools - Faceswap AI Online FREE
Faceswap AI Online
Swap Faces Video, Photo & GIFs Instantly with Powerful AI Tools - Faceswap AI Online FREE
Powerful AI Presentation PPT Maker for FREE
Build an impressive presentation with our free online AI presentation app
Your next top AI Assistant
Claude AI, developed by Anthropic
Your next top AI Assistant
Claude AI, developed by Anthropic
Temu Free $500 for New Users
Claim Free Temu $500 Credit via Affiliate & Influencer Program
Free TikTok Ads Credit
Master TikTok Ads for Your Business Marketing
Dall-E-OpenAI.com
Generate creative images automatically with AI
chatGPT4.win
Talk to ChatGPT by your mother language
First AI Product from Elon Musk - Grok/UN.com
Speak to Grok AI Chatbot with Your Language
Tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools
GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project
iPhoneKer.com
Save up to 630$ when buy new iPhone 16
Buy Tesla Optimus Robot
Order Your Tesla Bot: Optimus Gen 2 Robot Today for less than $20k