How to add html glyph markup to JQuery show/hide function
Tags: jquery,html,css,css3
Problem :
I have a very basic show/hide function that slides a sticky header up and down to reveal more contents. I've managed to get the trigger to change the text to the appropriate wording when the container is opened or closed but Id like to also add an up arrow and down arrow glyph to the appended text as well. How can this be achieved?
The output that I'm looking for should look something like this:
↓ Expand Playlist
↑ Close Playist
Below is what my markup looks like thus far:
HTML
<div id="sticky_header">
<div id="sticky_content" class="player">
<a href="#" id="toggle_sticky_header">Expand Playlist</a>
</div>
</div>
CSS
/*
-------------------------------------------------------------------------
Sticky Header
-------------------------------------------------------------------------
*/
#sticky_header {
background-color: #000000;
/* border-bottom: 5px solid #B54000; */
border-bottom: 5px solid #0995B0;
/* height: 100px; */
height: 600px;
min-width: 100%;
width: 100%;
position: fixed;
top: -500px;
left: 0px;
z-index: 2000;
box-shadow: 0px 1px 15px #000000;
-moz-box-shadow: 0px 1px 15px #000000;
-webkit-box-shadow: 0px 1px 15px #000000;
}
#sticky_content {
margin: 0px auto;
width: 990px;
padding: 15px 0px;
color: #FFFFFF;
position: relative;
}
a#toggle_sticky_header {
position: absolute;
bottom: -560px;
right: 0px;
color: #0995B0;
font-size: 10px;
line-height: 10px;
text-transform: uppercase;
}
JQUERY
<!-- Toggle sticky header -->
<script type="text/javascript">
$(document).ready(function(){
$('#toggle_sticky_header').click(function(){
if($("#sticky_header").css("top") == "-500px") {
$("#sticky_header").animate({top: "0px"}, 500);
} else {
$("#sticky_header").animate({top: "-500px"}, 500);
}
$(this).toggleClass("active");
if ($(this).html() == "Expand Playlist") {
$(this).html("Close Playlist");
}
else if ($(this).html() == "Close Playlist") {
$(this).html("Expand Playlist");
}
return false;
});
});
</script>
Solution :
Given that you're using html()
, you could simply use the html entity:
if ($(this).html() == "Expand Playlist") {
$(this).html("↑ Close Playlist");
}
else if ($(this).html() == "Close Playlist") {
$(this).html("↓ Expand Playlist");
}
Though I'd suggest a slight amendment:
$(this).html(function(i,h){
return h == '↓ Expand Playlist' ? '↓ Expand Playlist' : '↑ Expand Playlist'
});
References:
CSS Howto..
This is how I would do it: #table1 td { border: solid 1px black; } #table1 table td { border: none; } Live demo: http://jsfiddle.net/kbVH2/3/...
I have a wrapper function that I use to init the RTE. Try doing something along these lines, which is similar to what @MiniRagnarok posted. I just ran a test...
I think a better way to accomplish this would be to refactor your code so that each paragraph is its own <p>. I'd recommend putting all of them into a...
First of all - why mixing client-side/server-side code? You cannot use JS variable along with server-side generated content because - as you said - it is executed on server before...
I assume from your CSS, your HTML should be like that: <blockquote> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex cupiditate tenetur corporis officia corrupti at mollitia quam deleniti...
here is my suggestion: Use an ID for "dummy", if you have more than one "dummy" in your dom-tree you get an array with html elements from jquery. $(document).ready(function() {...
Is this what you are looking for? I gave the popup a parent container that will serve as the overlay. HTML: <div class="overlay"> <div id="welcome"> <span id="close"></span> This is the...
As far as a CSS solution goes, you'd need to specify a specific height for both of the divs. If you don't want to mess around with getting the CSS...
In order for GWT to report any CSS errors (misspelled/missing class names), you need to be including your CSSs in your GWT project via CssResource (check out the docs for...
few things going on here: your comment box div has a fixed height of 100px all the elements inside this div are absolutely positioned, which takes them out of the...
#nav_main li:first-child{background:red;} Here you can find everything you need to know: http://www.w3.org/TR/CSS21/selector.html...
the icon-circle parent need to be in table display mode .col-md-3 { display: table; } ...
Most Rich HTML online editors bring a "styles" drop down that allows the user to pick styles. See e.g. here for how it's solved in FCKEditor. As for what styles...
In the template there is a line of HTML that looks like this: <div id="sidebar" class="sidebar responsive"> You need to add the sidebar-fixed class like this: <div id="sidebar" class="sidebar sidebar-fixed...
You need to increase the specificity of that selector to have it override a rule with a lower selector specificity. So if you assign the class to the li element,...
For that You can scan user Agent and find out which browser, its version. Including the OS for OS specific styles You can use various CSS Hacks for specific browser...
click on the 'Text' tab on the top right of the editor to add HTML markup.
Since you are only using transition and already have the toggleClass method, you don't need to change anything in the JS to reverse the transition effect. All that you need...
You should have access to a .css CSS file. That is the 'Styles' for your site. (.html is the markup/content`) etc. ~ If you can find a place that has...
I haven't been able to find any workaround to get CSS selectors working in the search bar again. Rejoice, for they have returned! In any case, you can still use...
Add line-height:40px; to your div a#drop class FIDDLE div a#drop { display: block; background-color: #283744; width: 70%; position: relative; color:#fff; height: 40px; line-height:40px; /* <--- */ padding-left: 20px; font-size: 11pt;...
If you change position: absolute to position: fixed it will work in all browsers except IE6. This fixes the div to the viewport, so it doesn't move out of view...
For something like reversi, I think a table is appropriate — beyond the visuals, it’s a decent semantic representation of the content, i.e. the state of the game board. (<div>s...
The body tag has a default margin property. Use the following CSS code to get rid of the default margin: body { margin:0; } ...
This is not possible, as it does not seem all that sensible in the first place (applying a hover for example to an element where the default style is already...
Don't load the stylesheet inline. You can link to style sheets externally like this: <link rel="stylesheet" type="text/css" href="http://www.mystyle.css"> That way, the background images will be relative to where the stylesheet...
<div style="float:right;"> Right div </div> <div> Left div </div> ...
a HTML5 solution would be to use media queries to style the page differently depending on width: <link rel="stylesheet" type="text/css" media="screen" href="css/base.css" /> <link rel="stylesheet" type="text/css" media="screen and (min-width: 960px)"...
you can do this by $_GET <?php if(isset($_GET['param']) && $_GET['param'] ==youwant){ ?> //css <?php } ?> ...
You could try adding an empty li and style it as your separator. I think that would be ugly codewise, but something like this works: CSS: #nav { padding:0; margin:0;...