Reputation: 939
I'm currently working on this:
<div id='container'>
<div id="box1">
<h1>Share it!</h1>
</div>
<div class="box" style="visibility: hidden">
<a href="#" class="bt btleft">Facebook Button here</a>
<a href="#" class="bt btright">Twitter Button here</a>
</div>
</div>
$("#container").hover(function () {
$("#container div").css("visibility","visible");
},
function () {
$("#container div").css("visibility","hidden");
});
What I want to achieve is something like the website Mashable
What i want to achieve is when I hover on the word "share It!", it will auto hide and show the links (on the same exact location). I've been stuck here for a while, can someone help?
Upvotes: 4
Views: 4632
Reputation: 2880
Does this work for you? I think its simple and works for you
$("#container").hover(function () {
$(".box").css("visibility", "visible");
}, function () {
$(".box").css("visibility", "hidden");
});
Upvotes: 0
Reputation: 795
Use the html function which load dynamically content in a parent. Sample: http://jsfiddle.net/slown1/TqGFQ/
Here is the solution:
HTML:
<div id='container' style="border:1px solid red;">
<h1>Share it!</h1>
</div>
JS:
$("#container").hover(function () {
$("#container").html("<a href='#' "+
"class='bt btleft'>"+"Facebook Button here</a><a href='#'" +
"class='bt btright'>Twitter Button here</a>'");
},
function () {
$("#container").html("<h1>Share it!</h1>");
});
Upvotes: 1
Reputation: 12375
you need to hide box1 upon hover and show upon hover out
$("#container").hover(function () {
$('#box1').hide();
$('.box').show();
},
function () {
$('.box').hide();
$('#box1').show();
});
and your html
<div id="box1">
<h1>Share it!</h1>
</div>
<div class="box" style="display:none">
<a href="#" class="bt btleft">Facebook Button here</a>
<a href="#" class="bt btright">Twitter Button here</a>
</div>
Upvotes: 0
Reputation: 6110
With a little bit of changes in your HTML, this is something you might find useful. Simply use the .hover functionality of jQuery to toggle the states.
HTML
<div class="social">
<h1>Share this</h1>
<div class="networks">
<p>Twitter</p>
<p>Facebook</p>
</div>
</div>
CSS
.networks {
display:none;
}
JS
$(".social").hover(function() {
$("h1", this).hide();
$(".networks", this).fadeIn();
}, function() {
$(".networks", this).hide();
$("h1", this).fadeIn();
});
The fadeIn()
is just added for a nice fading effect, you can also use .show()
there.
Upvotes: 5