【问题标题】:How to make it so that when you scroll over a button a menu appears如何使它在您滚动按钮时出现菜单
【发布时间】:2017-01-20 02:24:15
【问题描述】:

在我的帖子下方的阅读更多链接旁边的首页上,我想添加一个社交分享菜单。但是,我只希望在用户将鼠标悬停在共享按钮上时显示共享菜单。类似于下面的图片。我添加了所有菜单链接和初始共享按钮。但是,当您将鼠标悬停在按钮上时,我无法弄清楚如何使菜单出现。有没有人有任何解决方案?这是一个小提琴 - https://jsfiddle.net/wow3820z/

分享按钮

悬停时分享按钮(显示社交分享菜单)

我的社交分享 html

<div class="share-buttons">

<a href="http://twitter.com/home/?status=Love this post by @ <?php the_title(); ?> - <?php the_permalink(); ?>" target="_blank" title="Tweet this!"><img src="https://www.theclimategroup.org/sites/all/modules/custom/tcg_social_media_icons/icons/black/16x16/twitter.png"></a>
   
<a href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
        <img src="http://www.shipwreckmuseum.com/wp-content/themes/shipwreckmuseum/assets/facebook-icon.png" alt="Facebook" />
    </a>
    
 <a href="javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)%7D)());">
        <img src="https://lh4.googleusercontent.com/-FaD4j4FL1Bc/TuEf9aN1gEI/AAAAAAAABek/kVqztZRwJ1w/s128/Pinterest_Favicon.png" alt="Pinterest" />
    </a>
    
    <a href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
        <img src="http://www.ihatestevensinger.com/osafe_theme/images/user_content/images/icon-heart.png" alt="Heart" />
    </a>

</div>

【问题讨论】:

    标签: javascript jquery html css hover


    【解决方案1】:

    将它们包装在容器/包装器中,隐藏共享按钮,当您将鼠标悬停在包装器上时,显示共享按钮。

    .wrap:hover .share-buttons {
      display: block;
    }
    .share-buttons {
      display: none;
    }
    <div class="wrap">
    
      <img class="main-share button" src="http://amandoblogs.com/wp-content/uploads/2014/08/share-e1408475480528.png" />
    
      <div class="share-buttons">
    
        <a href="http://twitter.com/home/?status=Love this post by @ <?php the_title(); ?> - <?php the_permalink(); ?>" target="_blank" title="Tweet this!"><img src="https://www.theclimategroup.org/sites/all/modules/custom/tcg_social_media_icons/icons/black/16x16/twitter.png"></a>
    
        <a href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
          <img src="http://www.shipwreckmuseum.com/wp-content/themes/shipwreckmuseum/assets/facebook-icon.png" alt="Facebook" />
        </a>
    
        <a href="javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)%7D)());">
          <img src="https://lh4.googleusercontent.com/-FaD4j4FL1Bc/TuEf9aN1gEI/AAAAAAAABek/kVqztZRwJ1w/s128/Pinterest_Favicon.png" alt="Pinterest" />
        </a>
    
        <a href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
          <img src="http://www.ihatestevensinger.com/osafe_theme/images/user_content/images/icon-heart.png" alt="Heart" />
        </a>
    
      </div>
    </div>

    【讨论】:

    • 它可以工作,但是即使您滚动到靠近主共享按钮的位置,菜单也会显示。你明白我的意思吗?您可以远离主共享按钮,并且菜单仍然会出现。我希望只有在您滚动按钮区域时才会显示社交共享菜单。这可能吗?
    • 另外 - 我把这个社交按钮放在另外两个按钮旁边。我希望它让这个社交按钮始终保持在其他两个按钮旁边,然后当您将鼠标悬停在社交按钮上时,社交共享菜单会出现在下方。如果您看一下这个小提琴,您会看到社交分享按钮位于其他两个按钮上方,而社交分享菜单位于其他两个按钮旁边? - jsfiddle.net/5mgoktLs/1
    【解决方案2】:

    我编辑了你的小提琴。

    关于html

    <div class="share-buttons" id='sharebuttons' style='display:none'>
    
    <a id="twitter" href="http://twitter.com/home/?status=Love this post by @ <?php the_title(); ?> - <?php the_permalink(); ?>" target="_blank" title="Tweet this!"><img src="https://www.theclimategroup.org/sites/all/modules/custom/tcg_social_media_icons/icons/black/16x16/twitter.png"></a>
    
    <a href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
            <img src="http://www.shipwreckmuseum.com/wp-content/themes/shipwreckmuseum/assets/facebook-icon.png" alt="Facebook" />
        </a>
    
     <a href="javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)%7D)());">
            <img src="https://lh4.googleusercontent.com/-FaD4j4FL1Bc/TuEf9aN1gEI/AAAAAAAABek/kVqztZRwJ1w/s128/Pinterest_Favicon.png" alt="Pinterest" />
        </a>
    
        <a id='heart' href="http://www.facebook.com/sharer.php?url=<?php the_permalink(); ?>" target="_blank">
            <img src="http://www.ihatestevensinger.com/osafe_theme/images/user_content/images/icon-heart.png" alt="Heart" />
        </a>
    
    </div>
    

    使用原生 javascript

    var mainsharebutton = document.getElementById('mainsharebutton');
    
    mainsharebutton.addEventListener('mouseover', showMenu);
    mainsharebutton.addEventListener('mouseleave', hideMenu);
    
    function showMenu(){
            var myMenu = document.getElementById('sharebuttons');
        myMenu.style.display = 'block';
    }
    
    function hideMenu(){
            var myMenu = document.getElementById('sharebuttons');
        myMenu.style.display = 'none';
    }
    

    基本上只是在您的分享按钮上添加鼠标事件 onmouseover 和 onmouseleave,然后我根据触发的事件显示或取消显示按钮 div

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-17
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多