• 0

2nd menu option with jQuery


Question

http://www.romabio.com/products/preview.html <--- My Example /

http://www.redbox.com/movies <--- What I'm trying to do /

https://www.neowin.net/forum/topic/1131050-jquery-quicksand/ <--- First post about this /

If you remember, I was trying to get quicksand working and someone help me with doing a short jQuery code to do the same thing. Well, everything is working great with just doing one menu but now. I would like to add on to it so that their is a second option for the user to select. I provided the link to My Example. I don't know how to right the code in jQuery so that the user can also sort the list in to Interior or Exterior like they did in the Redbox movie list. I don't think it would be really hard for someone that knows jQuery to quickly right the code for me. I'm more of a front-end web designer and then a back-end one.

I put the code below but not all of the product DIV code because it's mostly the same thing just the li class and h1 is different.


<div id="dropdown">
<ul class="filter">
<li>Product Information List
<ul>
<li class="current"><a href="#">All Products</a></li>
<li><a href="#">Limewash Products</a></li>
<li><a href="#">Slaked Lime Plasters</a></li>
<li><a href="#">3.5 NHL Cements</a></li>
<li><a href="#">Potassium Silcate Paints</a></li>
<li><a href="#">Silossanic Paints</a></li>
<li><a href="#">Stain & Varnishes</a></li>
<li><a href="#">Specialty Products</a></li>
</ul>
</li>
</ul>
</div>
<div id="dropdown2">
<ul class="filter">
<li class="current"><a href="#">All</a></li>
<li id="drop2"><a href="#">Interior</a></li>
<li id="drop3"><a href="#">Exterior</a></li>
</ul>

</div>
</div>




<ul class="items">

<li class="Limewash Products">
<a href="#"><div class="science-list shadow horizontal">
<img src="https://placehold.it/300x159" alt="" longdesc="" />
<h1>BioCalce Classico</h1>
</div></a>
</li>

<li class="Limewash Products">
<a href="#"><div class="science-list shadow horizontal">
<img src="https://placehold.it/300x159" alt="" longdesc="" />
<h1>BioCalce Classico A</h1>
</div></a>
</li>

</ul>
[/CODE]

[CODE]
<script type="text/javascript">
$('.filter li a').click(function() {

$(this).css('outline','none');
$('.filter .current').removeClass('current');
$(this).parent().addClass('current');

var filter = $(this).text();
if(filter == 'All Products') {
$('.items li.hidden').fadeIn('normal').removeClass('hidden');
} else {
$('.items li').each(function() {
if(!$(this).hasClass(filter)) {
$(this).fadeOut('normal').addClass('hidden');
} else {
$(this).fadeIn('normal').removeClass('hidden');
}
});
}

return false;
});

</script>
[/CODE]

Link to comment
https://www.neowin.net/forum/topic/1132088-2nd-menu-option-with-jquery/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

I can probably help you with this, but I'm not entirely sure what you are trying to accomplish...which part of the redbox menu are you trying to mimic? Is it the sorting functionality?

  • 0

Alright, I figured it out. It's kind of sloppy, but it gets the desired effect. You will still need to add in the Interior or Exterior class to each of your products, and change the class name for the second menu to "filter_2" for it to work. Other than that, you shouldn't have any issues. Here is the jQuery:


$('.filter li a').click(function() {

$(this).css('outline','none');
$('.filter .current').removeClass('current');
$(this).parent().addClass('current');

var filter = $(this).text();
var filter_2 = $('.filter_2 .current').text();
if(filter == 'All Products') {
if (filter_2=='All') {
$('.items li.hidden, .items h2.hidden').fadeIn('10000').removeClass('hidden');
}
else {
$('.items li, .items h2').each(function() {
if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
});
}
}
else {
$('.items li, .items h2').each(function() {
if (filter_2=='All') {
if (!$(this).hasClass(filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
}
else if(!$(this).hasClass(filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
});
}

return false;

});
$('.filter_2 li a').click(function() {
$('.filter_2 .current').removeClass('current');
$(this).parent().addClass('current');
var filter_2 = $(this).text();
var top_filter = $('.filter .current').text();
$('.items li, .items h2').each(function() {
if (top_filter=='All Products') {
if (filter_2=='All') {
$('.items li.hidden, .items h2.hidden').fadeIn('10000').removeClass('hidden');
}
else if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
}
else if (filter_2=='All') {
if (!$(this).hasClass(top_filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
}
else if (!$(this).hasClass(top_filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
});
});
[/CODE]

  • 0

Here is the final and working code in case anybody wanted to see the solution:


$('.filter li a').click(function() {

$(this).css('outline','none');
$('.filter .current').removeClass('current');
$(this).parent().addClass('current');
var filter = $(this).text();
var filter_2 = $('.filter_2 .current_2').text();
if(filter == 'All Products') {
if (filter_2=='All') {
$('.items li.hidden, .items h2.hidden').fadeIn('10000').removeClass('hidden');
}
else {
$('.items li, .items h2').each(function() {
if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
});
}
}
else {
$('.items li, .items h2').each(function() {
if (filter_2=='All') {
if (!$(this).hasClass(filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
}
else if(!$(this).hasClass(filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
});
}
return false;

});
$('.filter_2 li a').click(function() {
$('.filter_2 .current_2').removeClass('current_2');
$(this).parent().addClass('current_2');
var filter_2 = $(this).text();
var top_filter = $('.filter .current').text();
$('.items li, .items h2').each(function() {
if (top_filter=='All Products') {
if (filter_2=='All') {
$('.items li.hidden, .items h2.hidden').fadeIn('10000').removeClass('hidden');
}
else if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
}
else if (filter_2=='All') {
if (!$(this).hasClass(top_filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
}
else if (!$(this).hasClass(top_filter)) {
$(this).fadeOut('10000').addClass('hidden');
}
else if (!$(this).hasClass(filter_2)) {
$(this).fadeOut('10000').addClass('hidden');
}
else {
$(this).fadeIn('10000').removeClass('hidden');
}
});
});
[/CODE]

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Server Summit had a heap of announcements, ADCS changes are baller.
    • Nice, hope they *finally* fixed the issue with the NTFS driver where the system would completely brick during large file copies using the built in driver. It's been broken for years requiring me to use the older, slower, NTFS-3G FUSE driver.
    • Windows 11 KB5094126 BSODing, freezing, forcing BitLocker lockout, breaks OneDrive, and more by Sayan Sen Microsoft released Windows 11 KB5094126 and KB5093998 last week as the latest Patch Tuesday updates. Following that the company also published the accompanying dynamic updates under KB5094149, KB5095971, and KB5094156. While Microsoft has so far not acknowledged any major problems with the release, some users online are running into problems. These range from OneDrive and Dropbox access issues, BitLocker recovery lockouts, to blue screens and BSODs. The most common one seems to be happening with HP systems wherein affected users say they hit 0xc0430001 BSOD (blue screen of death) error code after the KB5094126 update. We wonder if this could be related to the recent bug we covered on HP devices wherein the ongoing Secure Boot certificate updates are leading to similar issues. While we are not certain, users affected by this issue likely need to ensure that the boot.stl file is included on the installation media (such as a USB installer or ISO), if the above-mentioned dynamic updates are deployed. If this file is missing, computers may fail to boot from the installation media and could display the error 0xc0430001. This STL file is used by Secure Boot to verify that the boot files are trusted, so it must match the same Windows version and system architecture. To ensure the file is included, Microsoft recommends using the Update WinPE script, which automatically updates the image and handles the required files. Alternatively, you can manually copy the boot.stl file from the Windows\Boot\EFI folder on a Windows device and place it in the matching folder on your installation media before deploying the updated image. Aside from blue screening some users also note their systems have been freezing following the update. This could be happening to Lenovo PCs specifically. In the case of the OneDrive and Dropbox access issues, a user figured out that there could be a conflict with UAC. He explained: "Okay, so I did some digging, and in our environment KB5094126 breaks OneDrive and Dropbox in Explorer. I went through all our GPOs and found out that the combination of disabling UAC and having my user being a local admin breaks OneDrive in Explorer. ... If I enable UAC again, then it works, even with KB5094126 still installed." Hopefully, Microsoft will look into these issues. Source: Microsoft forum (link1, link2, link3, link4), Reddit (link1, link2, link3, link4)
    • It is when it's a desktop in my house though for a PC that's lightly used and not really important when it is. If it was a laptop, it would be a different story. The real solution is varied and begins starting at post #22 in that thread.
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      138
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      81
  • Tell a friend

    Love Neowin? Tell a friend!