我有一系列社交网络按钮,在社区中找到,我想在其中一个按钮上放一个,当我将鼠标悬停在它上面时,它会自动显示更多社交网络按钮。我找不到它,而且我搜索了很多,我只看到了CODEPEN 示例, 但代码不存在,所以我不知道该怎么做。我希望我已经解释了自己,以便您可以帮助我了解我向您展示的内容,或者告诉我在哪里看。谢谢。
$(function() {
const ARTICLE_TITLE = document.title;
const ARTICLE_URL = encodeURIComponent(window.location.href);
const MAIN_IMAGE_URL = encodeURIComponent($('meta[property="og:image"]').attr('content'));
$('.share-fb').click(function(){
open_window('http://www.facebook.com/sharer/sharer.php?u='+ARTICLE_URL, 'facebook_share');
});
$('.share-twitter').click(function(){
open_window('http://twitter.com/share?url='+ARTICLE_URL, 'twitter_share');
});
$('.share-google-plus').click(function(){
open_window('https://plus.google.com/share?url='+ARTICLE_URL, 'google_share');
});
$('.share-linkedin').click(function(){
open_window('https://www.linkedin.com/shareArticle?mini=true&url='+ARTICLE_URL+'&title='+ARTICLE_TITLE+'&summary=&source=', 'linkedin_share');
});
$('.share-pinterest').click(function(){
open_window('https://pinterest.com/pin/create/button/?url='+ARTICLE_URL+'&media='+MAIN_IMAGE_URL+'&description='+ARTICLE_TITLE, 'pinterest_share');
});
$('.share-tumblr').click(function(){
open_window('http://www.tumblr.com/share/link?url='+ARTICLE_URL+'&name='+ARTICLE_TITLE+'&description='+ARTICLE_TITLE, 'tumblr_share');
});
function open_window(url, name){
window.open(url, name, 'height=320, width=640, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');
}
});
.share-buttons-row{
height: 40px;
display: -webkit-flex;
-webkit-align-items: center;
display: flex;
align-items: center;
}
.share-buttons-row >div:hover {
transform: rotate(360deg);
border-radius: 100px;
}
.share-buttons-row > div {
width: 40px;
height: 40px;
cursor: pointer;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
text-align: center;
float: left;
margin-right: .3em;
padding: 0;
background-repeat: no-repeat;
background-position: center;
background-size: 20px 20px;
}
.share-fb{
background-color: #2d609b;
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTI2LjY2NyAwaC0yMS4zMzRjLTIuOTQ1IDAtNS4zMzMgMi4zODgtNS4zMzMgNS4zMzR2MjEuMzMyYzAgMi45NDYgMi4zODcgNS4zMzQgNS4zMzMgNS4zMzRoMTAuNjY3di0xNGgtNHYtNGg0di0zYzAtMi43NjEgMi4yMzktNSA1LTVoNXY0aC01Yy0wLjU1MiAwLTEgMC40NDgtMSAxdjNoNS41bC0xIDRoLTQuNXYxNGg2LjY2N2MyLjk0NSAwIDUuMzMzLTIuMzg4IDUuMzMzLTUuMzM0di0yMS4zMzJjMC0yLjk0Ni0yLjM4Ny01LjMzNC01LjMzMy01LjMzNHoiPjwvcGF0aD48L3N2Zz4=);
}
.share-twitter{
background-color: #00c3f3;
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0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MC42ODUgMi40OS0xLjIxMSAwLjYyLTAuNTI3IDEuMTE2LTEuMTU4IDEuNDktMS44OTYgMC4zNzUtMC43MzYgMC42MzMtMS42NzYgMC43NzQtMi44MTVoMy4xNDF2NS4xMDhoNS4xMDV2My45NDFoLTUuMTA2djUuNjYyYzAgMS4yODEtMC4wMTcgMi4wMjAgMC4xMTkgMi4zODMgMC4xMzUgMC4zNjEgMC40NzMgMC43MzYgMC44NDEgMC45NTMgMC40ODkgMC4yOTMgMS4wNDcgMC40MzkgMS42NzYgMC40MzkgMS4xMTggMCAyLjIzMS0wLjM2MyAzLjMzNi0xLjA5MHYzLjQ4MnoiPjwvcGF0aD48L3N2Zz4=);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mas botones</title>
</head>
<body>
<!-- Buttons, Copy this to your Page Article -->
<div class="share-buttons-row">
<!--Facebook's Button -->
<div class="share-fb"></div>
<!--Twitter's Button -->
<div class="share-twitter"></div>
<!--Facebook's Button -->
<div class="share-google-plus"></div>
<!--Linkedin's Button -->
<div class="share-linkedin"></div>
<!--Pinterest's Button -->
<div class="share-pinterest"></div>
<!--Tumblr's Button -->
<div class="share-tumblr"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</body>
您可以使用
mouseenter
和函数mouseleave
来检测鼠标何时悬停在按钮上。然后函数
show
或hide
显示或隐藏,传递一个可选的毫秒参数,使动画更具吸引力。这是另一个根本不需要任何 JavaScript 的示例,只需使用 CSS,您就可以得到您想要的。这个问题更像是“你想要什么?”
我让您的 HTML 和 JS 代码完全相同,稍微更改了代码
.share-buttons-row
并添加了悬停效果。总的来说,我在您的代码中更改/添加的唯一内容是以下三个规则:在这里你可以看到它的工作:
从那里开始,您可以通过添加 CSS 动画/过渡来使其更加活跃,例如通过逐个显示按钮来使宽度逐渐增长(只需在 CSS 中添加 2 行即可):