1

在我正在做的脚本上需要一些帮助......我想要完成的是,当您将鼠标悬停在任何一类“测试”上时,#socializethis div 将显示。当您将鼠标移出时,它会消失。我已经实现了这一点,但是,我需要它在实际结束#socializethis 时保持专注,这样盒子就不会消失。

我想做但不知道该怎么做的第二件事是确定 a 类“测试”的位置,这样我就可以在它旁边、下面等显示框。

我将尝试将其用于社交共享脚本。

索引.html

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="share.js"></script>
<link rel="stylesheet" href="share.css" type="text/css" />

</head>

<body>
<div id="social">
<a class="test" href="#">share this</a>
</div>
</body>

</html>

分享.css

img {border: none;}
#socializethis{
 height:37px;
 width:260px;
 position:absolute;
 bottom:500px;
 right:900px;
 overflow:hidden;
 display:none;
 visibility:hidden;
 padding:3px 3px 3px 3px;
 /* CSS3 */
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
 border-radius: 10px;
 -moz-box-shadow: 0 0 3px 3px #555;
 -webkit-box-shadow: 0 0 3px 3px #555;
 box-shadow: 0 0 3px 3px #555;
}

#socializethis a{
 float:left; 
 width:32px;
 margin:3px 3px 3px 3px; 
 padding:0; 
}

#socializethis span{ 
 float:left; 
 margin:3px 3px 3px 3px;
 text-shadow: 1px 1px 1px #FFF;
 color:#444;
 font-size:12px;
}

分享.js

(function( $ ) {
  $(document).ready(function() { 

  var twit = 'http://twitter.com/home?status='+title+'%20'+url;
  var facebook = 'http://www.facebook.com/sharer.php?u='+url
  var digg = 'http://digg.com/submit?phase=2&url='+url+'&amp;title='+title;
  var stumbleupon = 'http://stumbleupon.com/submit?url='+url+'&amp;title='+title;
  var buzz = 'http://www.google.com/reader/link?url='+url+'&amp;title='+title+'&amp;srcURL='+host;
  var delicious  = 'http://del.icio.us/post?url='+url+'&amp;title='+title;

  var tbar = '<div id="socializethis"><span>Share<br /><a href="#min" id="minimize" title="Minimize"><img src="images/minimize.png" /> </a></span><div id="sicons">';
  tbar += '<a href="'+twit+'" id="twit" title="Share on twitter"><img src="images/twitter.png"  alt="Share on Twitter" width="32" height="32" /></a>';
  tbar += '<a href="'+facebook+'" id="facebook" title="Share on Facebook"><img src="images/facebook.png"  alt="Share on facebook" width="32" height="32" /></a>';
  tbar += '<a href="'+digg+'" id="digg" title="Share on Digg"><img src="images/digg.png"  alt="Share on Digg" width="32" height="32" /></a>';
  tbar += '<a href="'+stumbleupon+'" id="stumbleupon" title="Share on Stumbleupon"><img src="images/stumbleupon.png"  alt="Share on Stumbleupon" width="32" height="32" /></a>';
  tbar += '<a href="'+delicious+'" id="delicious" title="Share on Del.icio.us"><img src="images/delicious.png"  alt="Share on Delicious" width="32" height="32" /></a>';
  tbar += '<a href="'+buzz+'" id="buzz" title="Share on Buzz"><img src="images/google-buzz.png"  alt="Share on Buzz" width="32" height="32" /></a>';
  tbar += '</div></div>';

  // Add the share tool bar.
  $('#social').append(tbar);
  $('#socializethis').css({opacity: 1}); 

  // hover
  $('a.test').bind('mouseover',function(){
  $('#socializethis').animate({opacity: 1}, 600);
  $('#socializethis').css({display:'inline', visibility: 'visible'});   
  });

  $('#socializethis').bind('mouseover',function(){
  $('#socializethis').animate({opacity: 1}, 600);
  $('#socializethis').css({display:'inline', visibility: 'visible'});   
  });

  //leave
  $('a.test').bind('mouseout',function(){
    $('#socializethis').animate({opacity: 0}, 600, function(){
        $('#socializethis').css({display:'none', visibility: 'hidden'});   
    });
  }, 600);

  });
})(jQuery);
4

1 回答 1

2

要回答您的第一个问题 - 使用 jQuery 的 mouseenter 和 mouseleave 而不是 mouseover 和 mouseout。Mouseenter 将允许子级触发其父级的 mouseenter 事件。jQuery 页面http://api.jquery.com/mouseenter/在底部有一个很好的演示,展示了不同之处。然后将 test 和 socialize 元素放在父 div 中,虽然 socialize 是隐藏的,但它看起来只像 test。这样,除非用户离开两个元素,否则不会调用 mouseleave。

于 2011-08-13T02:09:54.917 回答