问题描述
在我正在做的脚本上需要一些帮助...我想要完成的是当你将鼠标悬停在#socializethis div将显示的任何一类'test'上时。当你使用鼠标时它会消失。我已经完成了这个,但是,我需要它保持专注,同时实际上超过#socializethis,所以盒子不会消失。
Need some help on a script I am doing... what I want to accomplish is when you hover over any a class of 'test' the #socializethis div will show. When you mouseout it will disappear. I have accomplished that, however, I need it to stay focused while actually over #socializethis as well so the box does not disappear.
我希望做的第二件事有不知道怎么去确定一个'测试'的位置,所以我可以在它旁边显示方框,在它下面等等。
Second thing I wish to do and have no idea how to go about is determine the position of the a class 'test' so I can show the box right beside it, under it, etc.
我要去尝试将此用作社交分享脚本。
Im going to try and use this for a social sharing script.
index.html
index.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>
share.css
share.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;
}
share.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+'&title='+title;
var stumbleupon = 'http://stumbleupon.com/submit?url='+url+'&title='+title;
var buzz = 'http://www.google.com/reader/link?url='+url+'&title='+title+'&srcURL='+host;
var delicious = 'http://del.icio.us/post?url='+url+'&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);
推荐答案
回答你的第一个问题 - 使用jQuery的mouseenter和mouseleave而不是鼠标悬停和mouseout。 Mouseenter将允许孩子触发他们父母的mouseenter事件。 jQuery页面在底部有一个很好的演示显示差异。然后将测试和社交元素放在父div中,虽然社交隐藏,但看起来只是测试。这样就不会调用mouseleave,除非用户同时保留这两个元素。
To answer your first question - use jQuery's mouseenter and mouseleave instead of mouseover and mouseout. Mouseenter will allow children to trigger their parent's mouseenter event. The jQuery page http://api.jquery.com/mouseenter/ has a good demo at the bottom showing the difference. Then put both test and socialize elements in a parent div, which while socialize is hidden, will look only like test. This way mouseleave will not be called unless the user leaves both elements.
这篇关于在脚本上需要帮助 - jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!