Question

I have 18 links within a div id="rplan_cat"

I would like each link open an overlay with css transitions within "rplan_cat" covering all the link contents within. If this is possible, can anyone direct me on the best approach with jquery?

Here is my page link: webpage

I attached an illustration of what I want: enter image description here

Here is my code:

<div id="rplan_cat">
   <div id="rplan_cat_title" style="min-width:66.4%;border-right:1px solid #4D4D4D;border-bottom:1px solid #FFF;">Recovery Plan Categories</div>
   <div id="rplan_cat_title" style="min-width:33.1%;border-bottom:1px solid #FFF;"></div>
             <a href="#" class="cat_width1 cat_medical">Medical Aid</a>
             <a href="#" class="cat_width1 cat_therapy">Therapy</a>
             <a href="#" class="cat_width2 cat_food">Food</a>
             <a href="#" class="cat_width1 cat_trans">Transportation</a>
             <a href="#" class="cat_width1 cat_counsel">Counseling</a>
             <a href="#" class="cat_width2 cat_job">Job Placement</a>
             <a href="#" class="cat_width1 cat_shelter">Shelter</a>
             <a href="#" class="cat_width1 cat_emerg">Emergencies</a>
             <a href="#" class="cat_width2 cat_school">Schooling</a>
             <a href="#" class="cat_width1 cat_house">Housing</a>
             <a href="#" class="cat_width1 cat_gear">Survival Gear</a>
             <a href="#" class="cat_width2 cat_reunion">Reunions</a>
             <a href="#" class="cat_width1 cat_legal">Legal Aid</a>
             <a href="#" class="cat_width1 cat_debt">Debt Relief</a>
             <a href="#" class="cat_width2 cat_bed">Bedding</a>
             <a href="#" class="cat_width1 cat_jobtrain">Job Training</a>
             <a href="#" class="cat_width1 cat_hygiene">Hygiene</a>
             <a href="#" class="cat_width2 cat_clothes">Clothing</a>
             <div style="width:100%;height:33px;float:left"></div>
 </div>

Here is the CSS:

#rplan_wrap                 {width: 100%;float:left;}
#rplan_wrap  .rplan         {width:160px;height:60px;line-height:60px;float:left;background:#C04747;color:#FFF;border-bottom: 0;font-family:'robotoregular' ;margin-top:20px;text-align:center;transition: background 0.5s ease-in-out;}
#rplan_wrap  .rplan:hover   {background:#4D4D4D;text-decoration:none;border-bottom: 0;}
#rplan_cat                  {width:100%;float:left;margin-top:30px;}
#rplan_cat_title            {height:50px;background:#4D4D4D; color:#FFF;font-size:.9em;float:left;line-height:50px;text-indent:25px}
#rplan_cat  a               {min-width:33.1%;height:110px;line-height: 150px;float:left;border:0;font-family:'robotoregular';text-align:center;color:#4D4D4D;font-size:.9em;transition: background 0.5s ease-in-out;}
.cat_width1                 {margin-right:1px;margin-bottom:1px}
.cat_width2                 {margin-bottom:1px}
.cat_medical                {background: #E6E6E6 url('img/cat_medical.png') 50% 23px no-repeat;}
.cat_medical:hover          {background: #E5FF17 url('img/cat_medical.png') 50% 23px no-repeat;}
.cat_therapy                {background: #E6E6E6 url('img/cat_therapy.png') 50% 23px no-repeat;}
.cat_therapy:hover          {background: #E5FF17 url('img/cat_therapy.png') 50% 23px no-repeat;}
.cat_food                   {background: #E6E6E6 url('img/cat_food.png')    50% 23px no-repeat;}
.cat_food:hover             {background: #E5FF17 url('img/cat_food.png')    50% 23px no-repeat;}
.cat_trans                  {background: #E6E6E6 url('img/cat_trans.png')   50% 23px no-repeat;}
.cat_trans:hover            {background: #E5FF17 url('img/cat_trans.png')   50% 23px no-repeat;}
.cat_counsel                {background: #E6E6E6 url('img/cat_counsel.png') 50% 23px no-repeat;}
.cat_counsel:hover          {background: #E5FF17 url('img/cat_counsel.png') 50% 23px no-repeat;}
.cat_job                    {background: #E6E6E6 url('img/cat_job.png')     50% 23px no-repeat;}
.cat_job:hover              {background: #E5FF17 url('img/cat_job.png')     50% 23px no-repeat;}
.cat_shelter                {background: #E6E6E6 url('img/cat_shelter.png') 50% 23px no-repeat;}
.cat_shelter:hover          {background: #E5FF17 url('img/cat_shelter.png') 50% 23px no-repeat;}

.cat_emerg {background: #E6E6E6 url('img/cat_emerg.png') 50% 23px no-repeat;} .cat_emerg:hover {background: #E5FF17 url('img/cat_emerg.png') 50% 23px no-repeat;} .cat_school {background: #E6E6E6 url('img/cat_school.png') 50% 23px no-repeat;} .cat_school:hover {background: #E5FF17 url('img/cat_school.png') 50% 23px no-repeat;} .cat_house {background: #E6E6E6 url('img/cat_house.png') 50% 23px no-repeat;} .cat_house:hover {background: #E5FF17 url('img/cat_house.png') 50% 23px no-repeat;} .cat_gear {background: #E6E6E6 url('img/cat_gear.png') 50% 23px no-repeat;} .cat_gear:hover {background: #E5FF17 url('img/cat_gear.png') 50% 23px no-repeat;} .cat_reunion {background: #E6E6E6 url('img/cat_reunion.png') 50% 23px no-repeat;} .cat_reunion:hover {background: #E5FF17 url('img/cat_reunion.png') 50% 23px no-repeat;} .cat_legal {background: #E6E6E6 url('img/cat_legal.png') 50% 23px no-repeat;} .cat_legal:hover {background: #E5FF17 url('img/cat_legal.png') 50% 23px no-repeat;} .cat_debt {background: #E6E6E6 url('img/cat_debt.png') 50% 23px no-repeat;} .cat_debt:hover {background: #E5FF17 url('img/cat_debt.png') 50% 23px no-repeat;} .cat_bed {background: #E6E6E6 url('img/cat_bed.png') 50% 23px no-repeat;} .cat_bed:hover {background: #E5FF17 url('img/cat_bed.png') 50% 23px no-repeat;} .cat_jobtrain {background: #E6E6E6 url('img/cat_jobtrain.png')50% 23px no-repeat;} .cat_jobtrain:hover {background: #E5FF17 url('img/cat_jobtrain.png')50% 23px no-repeat;} .cat_hygiene {background: #E6E6E6 url('img/cat_hygiene.png') 50% 23px no-repeat;} .cat_hygiene:hover {background: #E5FF17 url('img/cat_hygiene.png') 50% 23px no-repeat;} .cat_clothes {background: #E6E6E6 url('img/cat_clothes.png') 50% 23px no-repeat;} .cat_clothes:hover {background: #E5FF17 url('img/cat_clothes.png') 50% 23px no-repeat;}

Was it helpful?

Solution

Here's a FIDDLE

I created content div's with id matching to anchor 2nd class attribute to be able to target them with jQuery. You have everything in the Fiddle. If something's unclear feel free to ask.

HTML

<div id="cat_medical" class="content">
   Cat Medical
</div>

<div id="cat_therapy" class="content">
   Cat Therapy
</div>

<div id="cat_food" class="content">
   Cat Food
</div>

...

CSS

#rplan_cat {
  position:relative;
  width:100%;
  float:left;
  margin-top:30px;
}
.content {
  background: #e6e6e6;
  position: absolute;
  display: none;
  top: 50px;
  left: 0;
  width: 100%;
  height: 660px;
  padding: 15px;    
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}
.close {
  position: absolute;
  top: 15px;
  right: 15px;
  font-family: Verdana;
  font-size: 18px;
  font-weight: bold;
  color: #4d4d4d;
  cursor: pointer;
}

jQuery

(function($) {
  $('#rplan_cat a').click(function(e) {
    e.preventDefault();
    $('#'+$(this).attr('class').split(' ')[1]).fadeIn(400);
  });
  $('.content').append('<span class="close">X</span>');
  $('.close').on('click',function() {
    $('.content').fadeOut(400);
  });
})(jQuery);

OTHER TIPS

Here is a jsFiddle.

These are the basic concepts. Don't want them in a list? that's fine. Use divs or just the a, but note that the DOM traversal might be slightly different.

Also, there are many many more issues with page height and pitfalls to come with actually making this responsive, page scrolling - overflow etc - so be ready for that. (note that the javascript uses jQuery - so you'll need to include that. For future reference, all of that code you posted was useless. The first 4 lines of the html in your case would suffice. See the how bare this jsfiddle is and keep that in mind for next time. Your specific text or logos are of no consequence.

A lot of this hinges on full understanding of positioning. Relative, absolute, fixed, static. Currently I used fixed for the pop-up because if I used absolute, you might make a container relative, which would change everything, so keep that in mind. Understand how relative divs describe boundaries for elements within, that are absolute.

Data attributes would be great here to connect the icon and spotlight, but because you can't go back to see more icons, until you close the first, the specificity was not necessary.

I have an inner-wrapper called .text-w around the pop-up content so that we can have 2 transition effects. Note how I add the class to the outer element, and use that class to target all elements within instead of adding a class to each. This basically changing the context of an area instead of one element. Sass or Stylus would make this much easier to read and write due to it's nesting abilities.

HTML

<ul class="your-list">
    <li>
        <a href="#" class="icon">01</a>
        <div class="spotlight">
            <div class="text-w">
                <h1>Spotlight 01 name</h1>
                <p>bla bla bla</p>
                <button>close this</button>
            </div>
        </div>
    </li>
    <li>
        etc...
    </li>
</ul>

CSS

*, *:before, *:after {
    -moz-box-sizing: border-box; 
    -webkit-box-sizing: border-box; 
    box-sizing: border-box;
}

body {
    margin: 0;
}

a {
    text-decoration: none;
    color: inherit;
}

.your-list {
    list-style: none;
    margin: 0; padding: 0;
}

.your-list li {
    width: 25%;
    float: left;
    border: 1px solid gray;
}

.your-list a {
    display: block;
    background-color: lightgray;
    min-height: 5em;
    padding: 1rem;
}

.your-list .spotlight {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
/* width: 100%;
    height: 100%; */
    width: 0;
    height: 0;
    overflow: hidden;
    background: yellow;
    padding: 0;
    transition: all .5s ease-in-out;
    transition-delay: .2s;
}

.your-list .spotlight .text-w {
    opacity: 0;
    transition: opacity .2s ease-in-out;
}

.your-list .show-spotlight {
    width: 100%;
    height: 100%;
    background: red;
    padding: 1rem;
    transition: all .5s ease-in-out;
}

.your-list .show-spotlight .text-w {
    opacity: 1;
    transition: opacity .2s ease-in-out;
    transition-delay: .5s;
}

jQuery

$('.your-list .icon').on('click', function() {
    $(this).closest('li').find('.spotlight').addClass('show-spotlight');
});

$('.your-list .spotlight button').on('click', function() {
    $(this).closest('.spotlight').removeClass('show-spotlight');
});

jQuery explained...

/* when .icon is clicked... run this function... */
$('.icon').on('click', function() {
    /* $(this) means... the element the function is based on... 
    so in this case, .icon --- but not all .icon... 
    just the one you clicked... so it's relative to the specific action */
    $(this).closest('li').find('.spotlight').addClass('show-spotlight');
    /* so... with this icon... use closest() to traverse up the DOM tree nodes 
    and find the closest li... then go down the DOM tree and find the nearest .spotlight... 
    and add a class... you could use fadeIn() or something else too. 
    This class is what has the transitions in your CSS */
});

$('.spotlight button').on('click', function() {
    $(this).closest('.spotlight').removeClass('show-spotlight');
    /* when you click the button
    go up the DOM and find the closest .spotlight and remove the class 
    different transitions can happen when you add or remove based on your CSS*/
});

The reason for the DOM traversal, is that you might have stuff in-between this in the future - so .next() is no good.

You can see this CodePen for a more robust example, and the SCSS for it - and a clean way to target and style by list item.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top