经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » XHTML » 查看文章
html滑动仿悬浮球菜单效果的实现_HTML/Xhtml
来源:jb51  时间:2021/3/8 11:19:31  对本文有异议

css样式

  1. html,body{
  2. width: 100%;
  3. height: 100%;
  4. margin: 0;padding: 0;
  5. }
  6.  
  7. /*导航图标*/
  8. .NMH-g-navicon{
  9. position: fixed;
  10. top: 40%;
  11. right: 020px;
  12. width: 100px;
  13. height: 100px;
  14. }
  15. .NMH-g-navicon.Jnmh-onleft{
  16. right: auto;
  17. left: 020px;
  18. }
  19. /*导航图标logo按钮*/
  20. .NMH-g-navicon .Jnmh-btnlogo{
  21. position: absolute;
  22. display: block;
  23. width: 100px;
  24. height: 100px;
  25. top: 50%;
  26. right: 0;
  27. margin-top: -50px;
  28. border: 0;
  29. background: url(img/icon_128.png) no-repeat center center;
  30. background-size: 95% 95%;
  31. border: 1px solid rgba(0, 0, 0, 0.1);
  32. box-shadow: rgba(0, 0, 0, 0.12) 0px 6px 10px 0px;
  33. outline: none;
  34. border-radius: 50%;
  35. z-index: 1;
  36. }
  37. .NMH-g-navicon .Jnmh-btnlogohover{
  38. position: absolute;
  39. display: block;
  40. width: 100px;
  41. height: 100px;
  42. top: 50%;
  43. right: 0;
  44. margin: 0;padding: 0;
  45. margin-top: -50px;
  46. border: 0;
  47. overflow: hidden;
  48. /*background-color: red;*/
  49. }
  50.  
  51. /*导航图标logo按钮-鼠标经过*/
  52. .NMH-g-navicon.Jnmh-open .Jnmh-btnlogohover{
  53. margin-top: -150px;
  54. width: 200px;
  55. height: 300px;
  56. border-radius: 150px 0 0 150px;
  57. }
  58. .NMH-g-navicon.Jnmh-onleft .Jnmh-btnlogohover{
  59. left: 0;
  60. right: auto;
  61. border-radius: 0 150px 150px 0;
  62. }
  63. /*导航图标菜单子容器*/
  64. .NMH-g-navicon .Jnmh-m-submenu{
  65. position: absolute;
  66. background-color: transparent;
  67. list-style: none;
  68. top: -020px;
  69. bottom: -020px;
  70. left: -020px;
  71. right: -020px;
  72. margin: 0;
  73. padding: 0;
  74. }
  75.  
  76. .NMH-g-navicon .Jnmh-m-submenu .Jnmh-subli{
  77. position: absolute;
  78. width: 100%;height: 100%;
  79. transform: rotate(0deg);
  80. -webkit-transform: rotate(0deg);
  81. transition: all 0.8s ease-in-out;
  82. }
  83.  
  84. .Jnmh-m-submenu .Jnmh-subdl{
  85. position: absolute;
  86. left: 50%;
  87. bottom: 100%;
  88. width: 0;
  89. height: 0;
  90. line-height: 1px;
  91. margin-left: 0;
  92. background: #fff;
  93. border-radius: 50%;
  94. text-align: center;
  95. font-size: 1px;
  96. overflow: hidden;
  97. cursor: pointer;
  98. box-shadow: none;
  99. transition: all 0.8s ease-in-out, color 0.1s, background 0.1s;
  100. }
  101. /*导航图标-展开菜单时*/
  102. .NMH-g-navicon.Jnmh-open .Jnmh-m-submenu .Jnmh-subdl{
  103. width: 80px;
  104. height: 80px;
  105. line-height: 80px;
  106. margin-left: -40px;
  107. box-shadow: 0 3px 3px rgba(0, 0, 0, 0.1);
  108. font-size: 14px;
  109. }
  110. /*导航图标-三级菜单容器*/
  111. .NMH-g-navicon.Jnmh-open .Jnmh-m-submenu .Jnmh-subdd{
  112. position: absolute;
  113. line-height: normal;
  114. }

html代码

  1. <div id="nmh-navicon" class="NMH-g-plugin NMH-g-navicon">
  2. <button class="Jnmh-btnlogo"></button>
  3. <ins class="Jnmh-btnlogohover"></ins>
  4. <ul class="Jnmh-m-submenu">
  5. <li class="Jnmh-subli">
  6. <dl class="Jnmh-subdl">
  7. <dt class="NMH-subdt">电商平台</dt>
  8. <dd class="NMH-subdd"></dd>
  9. </dl>
  10. </li>
  11. <li class="Jnmh-subli">
  12. <dl class="Jnmh-subdl">
  13. <dt class="NMH-subdt">选品平台</dt>
  14. <dd class="NMH-subdd"></dd>
  15. </dl>
  16. </li>
  17. <li class="Jnmh-subli">
  18. <dl class="Jnmh-subdl">
  19. <dt class="NMH-subdt">会员升级</dt>
  20. <dd class="NMH-subdd"></dd>
  21. </dl>
  22. </li>
  23. <li class="Jnmh-subli">
  24. <dl class="Jnmh-subdl">
  25. <dt class="NMH-subdt">产品操作</dt>
  26. <dd class="NMH-subdd"></dd>
  27. </dl>
  28. </li>
  29. <li class="Jnmh-subli">
  30. <dl class="Jnmh-subdl">
  31. <dt class="NMH-subdt">个人中心</dt>
  32. <dd class="NMH-subdd"></dd>
  33. </dl>
  34. </li>
  35. </ul>
  36. </div>

javascript代码

  1. <script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  2. <script type="text/javascript">
  3. // 监听鼠标移入logo事件
  4. $(document).on('mouseenter','.Jnmh-btnlogo',function(){
  5. $('#nmh-navicon').addClass('Jnmh-open');
  6. GtoggleNavlogo();
  7. });
  8. // 监听鼠标移除导航球移除事件(展开收缩悬浮球为什么不直接监听#nmh-navicon而多了一步监听logo是为了减少边缘触发)
  9. $(document).on('mouseleave','#nmh-navicon',function(){
  10. $('#nmh-navicon').removeClass('Jnmh-open');
  11. GtoggleNavlogo();
  12. });
  13. var GtoggleNavlogo = function(){
  14. var li = $('#nmh-navicon').find('.Jnmh-subli');
  15. var lilen = li.length;
  16. var avgDeg = 180/(lilen-1);// 平均角度
  17. var initDeg = 0;// 起始方向角度
  18. if($('#nmh-navicon').hasClass('Jnmh-onleft')){
  19. // 如果悬浮球被拖拽到左边,则二级菜单则显示右侧
  20. li.css({transform: 'rotate(0deg)'});
  21. initDeg = 180;
  22. }else{
  23. // 默认悬浮球在右边,二级菜单显示在左侧
  24. li.css({transform: 'rotate(-360deg)'});
  25. }
  26. for(var i=0,j=lilen-1; i<lilen; i++,j--) {
  27. var d = initDeg - (i*avgDeg);
  28. var z = initDeg?j:i;
  29. // console.log(d);
  30. $('#nmh-navicon').hasClass('Jnmh-open') ? GrotateNavlogo(li[z],d) : GrotateNavlogo(li[z],0);
  31. }
  32. };
  33. var GrotateNavlogo = function(dom,deg){
  34. $({a:0}).animate({a:deg}, {
  35. step: function(now,fx) {
  36. $(dom).css({ transform: 'rotate('+now+'deg)' });
  37. $(dom).children().css({ transform: 'rotate('+(-now)+'deg)' });
  38. }, duration: 0
  39. });
  40. }
  41.  
  42. // 鼠标拖动logo移动
  43. $(document).on('mousedown','.Jnmh-btnlogo',function(e_down){
  44. var wrap = $('#nmh-navicon');
  45. wrap.removeClass('Jnmh-open');
  46. $('.Jnmh-m-submenu').hide();
  47. GtoggleNavlogo();
  48. var positionDiv = wrap.offset();
  49. var distenceX = e_down.pageX - positionDiv.left;
  50. var distenceY = e_down.pageY - positionDiv.top + $(document).scrollTop();
  51. $(document).mousemove(diy_move);
  52. function diy_move(e_move){
  53. var x = e_move.pageX - distenceX;
  54. var y = e_move.pageY - distenceY;
  55.  
  56. if (x < 0) {
  57. x = 0;
  58. } else if (x > $(document).width() - wrap.outerWidth(true)) {
  59. x = $(document).width() - wrap.outerWidth(true);
  60. }
  61.  
  62. if (y < 0) {
  63. y = 0;
  64. } else if (y > $(window).height() - wrap.outerHeight(true)) {
  65. y = $(window).height() - wrap.outerHeight(true);
  66. }
  67.  
  68. $(wrap).css({
  69. 'left': x + 'px',
  70. 'top': y + 'px'
  71. });
  72. }
  73. $(document).mouseup(function() {
  74. var x = $(wrap).offset().left;
  75. var rm = '',ad = 'Jnmh-open';
  76. if(x > $(document).width()/2){
  77. x = $(document).width() - wrap.outerWidth(true) -10 ;
  78. rm = 'Jnmh-onleft';
  79. }else{
  80. x = 10;
  81. ad += ' Jnmh-onleft';
  82. }
  83. $(wrap).css({left: x + 'px'}).addClass(ad).removeClass(rm);
  84. $('.Jnmh-m-submenu').show();
  85. GtoggleNavlogo();
  86. $(document).unbind('mousemove',diy_move);
  87. });
  88.  
  89. });
  90.  
  91. </script>

在这里插入图片描述

到此这篇关于html滑动仿悬浮球菜单效果的实现的文章就介绍到这了,更多相关html滑动仿悬浮球菜单内容请搜索w3xue以前的文章或继续浏览下面的相关文章,希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号