如何用HTML制作一个有趣的悬浮球菜单效果

Admin 2022-06-14 群英技术资讯 807 次浏览

很多朋友都对“如何用HTML制作一个有趣的悬浮球菜单效果”的内容比较感兴趣,对此小编整理了相关的知识分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获,那么感兴趣的朋友就继续往下看吧!

css样式

html,body{
	width: 100%;
	height: 100%;
	margin: 0;padding: 0;
}

/*导航图标*/
.NMH-g-navicon{
	position: fixed;
	top: 40%;
	right: 020px;
	width: 100px;
	height: 100px;
}
.NMH-g-navicon.Jnmh-onleft{
	right: auto;
	left: 020px;
}
/*导航图标logo按钮*/
.NMH-g-navicon .Jnmh-btnlogo{
	position: absolute;
	display: block;
	width: 100px;
	height: 100px;
	top: 50%;
	right: 0;
	margin-top: -50px;
	border: 0;
	background: url(img/icon_128.png) no-repeat center center;
    background-size: 95% 95%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: rgba(0, 0, 0, 0.12) 0px 6px 10px 0px;
	outline: none;
	border-radius: 50%;
	z-index: 1;
}
.NMH-g-navicon .Jnmh-btnlogohover{
	position: absolute;
	display: block;
	width: 100px;
	height: 100px;
	top: 50%;
	right: 0;
	margin: 0;padding: 0;
	margin-top: -50px;
	border: 0;
	overflow: hidden;
	/*background-color: red;*/
}

/*导航图标logo按钮-鼠标经过*/
.NMH-g-navicon.Jnmh-open .Jnmh-btnlogohover{
	margin-top: -150px;	
	width: 200px;
	height: 300px;
	border-radius: 150px 0 0 150px;
}
.NMH-g-navicon.Jnmh-onleft .Jnmh-btnlogohover{
	left: 0;
	right: auto;
	border-radius: 0 150px 150px 0;
}
/*导航图标菜单子容器*/
.NMH-g-navicon .Jnmh-m-submenu{
	position: absolute;
	background-color: transparent;
	list-style: none;
	top: -020px;
	bottom: -020px;
	left: -020px;
	right: -020px;
	margin: 0;
	padding: 0;
}

.NMH-g-navicon .Jnmh-m-submenu .Jnmh-subli{
	position: absolute;
	width: 100%;height: 100%;
	transform: rotate(0deg);
    -webkit-transform: rotate(0deg);
    transition: all 0.8s ease-in-out;
}

.Jnmh-m-submenu .Jnmh-subdl{
	position: absolute;
    left: 50%;
    bottom: 100%;
    width: 0;
    height: 0;
    line-height: 1px;
    margin-left: 0;
    background: #fff;
    border-radius: 50%;
    text-align: center;
    font-size: 1px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: none;
    transition: all 0.8s ease-in-out, color 0.1s, background 0.1s;
}
/*导航图标-展开菜单时*/
.NMH-g-navicon.Jnmh-open .Jnmh-m-submenu .Jnmh-subdl{
	width: 80px;
    height: 80px;
    line-height: 80px;
    margin-left: -40px;
    box-shadow: 0 3px 3px rgba(0, 0, 0, 0.1);
    font-size: 14px;
}
/*导航图标-三级菜单容器*/
.NMH-g-navicon.Jnmh-open .Jnmh-m-submenu .Jnmh-subdd{
	position: absolute;
	line-height: normal;
}

html代码

<div id="nmh-navicon" class="NMH-g-plugin NMH-g-navicon">
		<button class="Jnmh-btnlogo"></button>
		<ins class="Jnmh-btnlogohover"></ins>
		<ul class="Jnmh-m-submenu">
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">电商平台</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">选品平台</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">会员升级</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">产品操作</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">个人中心</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
		</ul>
	</div>

javascript代码

<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
	// 监听鼠标移入logo事件
	$(document).on('mouseenter','.Jnmh-btnlogo',function(){
		$('#nmh-navicon').addClass('Jnmh-open');
		GtoggleNavlogo();
	});
	// 监听鼠标移除导航球移除事件(展开收缩悬浮球为什么不直接监听#nmh-navicon而多了一步监听logo是为了减少边缘触发)
	$(document).on('mouseleave','#nmh-navicon',function(){
		$('#nmh-navicon').removeClass('Jnmh-open');
		GtoggleNavlogo();
	});
	var GtoggleNavlogo = function(){
	    var li = $('#nmh-navicon').find('.Jnmh-subli');
	    var lilen = li.length;
	    var avgDeg =  180/(lilen-1);// 平均角度
	    var initDeg = 0;// 起始方向角度
	    if($('#nmh-navicon').hasClass('Jnmh-onleft')){
	    	// 如果悬浮球被拖拽到左边,则二级菜单则显示右侧
	    	li.css({transform: 'rotate(0deg)'});
	    	initDeg =  180;
	    }else{
	    	// 默认悬浮球在右边,二级菜单显示在左侧
	    	li.css({transform: 'rotate(-360deg)'});
	    }
	    for(var i=0,j=lilen-1; i<lilen; i++,j--) {
	        var d =  initDeg - (i*avgDeg);
	        var z = initDeg?j:i;
	        // console.log(d);
	        $('#nmh-navicon').hasClass('Jnmh-open') ? GrotateNavlogo(li[z],d) : GrotateNavlogo(li[z],0);
	    }
	};
	var GrotateNavlogo = function(dom,deg){
		$({a:0}).animate({a:deg}, {
	        step: function(now,fx) {
	            $(dom).css({ transform: 'rotate('+now+'deg)' });
	            $(dom).children().css({ transform: 'rotate('+(-now)+'deg)' });
	        }, duration: 0
	    });
	}

	// 鼠标拖动logo移动
	$(document).on('mousedown','.Jnmh-btnlogo',function(e_down){
		var wrap = $('#nmh-navicon');
		wrap.removeClass('Jnmh-open');
		$('.Jnmh-m-submenu').hide();
		GtoggleNavlogo();
		
		var positionDiv = wrap.offset();
	    var distenceX = e_down.pageX - positionDiv.left;
	    var distenceY = e_down.pageY - positionDiv.top + $(document).scrollTop();
		$(document).mousemove(diy_move);
		function diy_move(e_move){
			var x = e_move.pageX - distenceX;
	        var y = e_move.pageY - distenceY;

	        if (x < 0) {
	            x = 0;
	        } else if (x > $(document).width() - wrap.outerWidth(true)) {
	            x = $(document).width() - wrap.outerWidth(true);
	        }

	        if (y < 0) {
	            y = 0;
	        } else if (y > $(window).height() - wrap.outerHeight(true)) {
	            y = $(window).height() - wrap.outerHeight(true);
	        }

	        $(wrap).css({
	            'left': x + 'px',
	            'top': y + 'px'
	        });
		}
		$(document).mouseup(function() {
			var x = $(wrap).offset().left;
			var rm = '',ad = 'Jnmh-open';
			if(x > $(document).width()/2){
				x = $(document).width() - wrap.outerWidth(true) -10 ;
				rm = 'Jnmh-onleft';
			}else{
				x = 10;
				ad += ' Jnmh-onleft';
			}
			$(wrap).css({left: x + 'px'}).addClass(ad).removeClass(rm);
			$('.Jnmh-m-submenu').show();
			GtoggleNavlogo();
	        $(document).unbind('mousemove',diy_move);
	    });

	});

</script>


到此这篇关于“如何用HTML制作一个有趣的悬浮球菜单效果”的文章就介绍到这了,更多相关内容请搜索群英网络以前的文章或继续浏览下面的相关文章,希望大家以后多多支持群英网络!
群英智防CDN,智能加速解决方案

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

猜你喜欢

成为群英会员,开启智能安全云计算之旅

立即注册
专业资深工程师驻守
7X24小时快速响应
一站式无忧技术支持
免费备案服务
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
在线客服
微信公众号
返回顶部
返回顶部 返回顶部
在线客服
在线客服