Solved

Multiple vertical sliding panels for social media links

Posted on 2013-06-25
5
347 Views
Last Modified: 2013-07-02
I want to create multiple vertical sliding panels on a page for social media links, etc

How can I edit the jquery in this demo please in order to display multiple panels?

http://spyrestudios.com/how-to-create-a-sexy-vertical-sliding-panel-using-jquery-and-css3/
0
Comment
Question by:aliciabutler
  • 2
  • 2
5 Comments
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 39274433
What you need to do is give your trigger buttons an id that is in some way linked to their corresponding panel. For instance

class="trigger" id="trigger1"

Then for the panel id would be something like

class="panel" id="trigger1_panel"

The JQuery then becomes as follows

$(document).ready(function(){
	    $(".trigger").click(function(){
	        $("#" + $(this).attr("id") + "_panel").toggle("fast");
	        $(this).toggleClass("active");
	        return false;
	    });
	});

Open in new window

0
 
LVL 42

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
ID: 39275413
Rather than concatenating one id from another, why not just use a data attribute to define the expanding div.

$(".trigger").click(function(){
    $("#" + $(this).data("panel")).toggle("fast");
    $(this).toggleClass("active");
});

<div class="trigger" data-panel="panel1">Trigger</div>
<div class="panel" id="panel1">This is a panel</div>

<div class="trigger" data-panel="panel2">Trigger</div>
<div class="panel" id="panel2">This is a panel</div>

<div class="trigger" data-panel="panel3">Trigger</div>
<div class="panel" id="panel3">This is a panel</div>

Open in new window

0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 39276157
@Chris ... because that takes more coding and I am a typical lazy programmer.

If the trigger is an <a> you can also put the id in the HRef attribute

The cost of retrieving it is effectively the same in all cases.

In your example you are concactenating the '#' which comes to the same thing. You could put the '#' in the data- attribute as well.

All much of a muchness at the end of the day.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39276594
$(this).attr("id") + "_panel"
$(this).data("panel")

It seems like less coding, but yeah, they're pretty much the same - personally, I just prefer to use the data attribute to store arbitrary data. Always nice to have options though :)
0
 

Author Closing Comment

by:aliciabutler
ID: 39293286
Works beautifully!  Thanks both of you
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now