4

我目前正在做这个:

<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");
});

http://jsfiddle.net/L9USt/3/

我想要实现的是类似于网站Mashable

我想要实现的是当我将鼠标悬停在“分享它!”这个词上时,它会自动隐藏并显示链接(在相同的确切位置)。我在这里卡了一段时间,有人可以帮忙吗?

4

4 回答 4

5

对您的 HTML 进行一些更改,您可能会发现这很有用。只需使用 jQuery 的.hover功能来切换状态。

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();
});

fadeIn()只是添加了一个很好的褪色效果,你也可以在.show()那里使用。

JSfiddle

于 2013-03-03T11:20:27.870 回答
1

使用在父项中动态加载内容的 html 函数。示例:http: //jsfiddle.net/slown1/TqGFQ/

这是解决方案:

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>");
      });
于 2013-03-03T11:29:23.193 回答
0

您需要在悬停时隐藏 box1 并在悬停时显示

 $("#container").hover(function () {
        $('#box1').hide();
        $('.box').show();     
   },
  function () {
       $('.box').hide();     
       $('#box1').show();
   });

和你的 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>
于 2013-03-03T11:17:20.390 回答
0

这对你有用吗?我认为它很简单,适合你

http://jsfiddle.net/mztcn/

$("#container").hover(function () {
    $(".box").css("visibility", "visible");
}, function () {
    $(".box").css("visibility", "hidden");
});
于 2013-03-03T14:02:59.687 回答