Implementation of HTML sliding floating ball menu effect

Implementation of HTML sliding floating ball menu effect

CSS Styles

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

/*Navigation icon*/
.NMH-g-navicon{
	position: fixed;
	top: 40%;
	right: 020px;
	width: 100px;
	height: 100px;
}
.NMH-g-navicon.Jnmh-onleft{
	right: auto;
	left: 020px;
}
/*Navigation icon logo button*/
.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;*/
}

/*Navigation icon logo button-mouse over*/
.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;
}
/*Navigation icon menu subcontainer*/
.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;
}
/*Navigation icon-when expanding the menu*/
.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;
}
/*Navigation icon-three-level menu container*/
.NMH-g-navicon.Jnmh-open .Jnmh-m-submenu .Jnmh-subdd{
	position: absolute;
	line-height: normal;
}

HTML code

<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">E-commerce platform</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">Product selection platform</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">Member Upgrade</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">Product Operation</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
			<li class="Jnmh-subli">
				<dl class="Jnmh-subdl">
					<dt class="NMH-subdt">Personal Center</dt>
					<dd class="NMH-subdd"></dd>
				</dl>
			</li>
		</ul>
	</div>

JavaScript code

<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
	// Listen for the mouse entering the logo event $(document).on('mouseenter','.Jnmh-btnlogo',function(){
		$('#nmh-navicon').addClass('Jnmh-open');
		GtoggleNavlogo();
	});
	// Listen for mouse removal of navigation ball removal events (why don't we listen to #nmh-navicon directly when expanding and contracting the floating ball? Instead, we listen to the logo one more time to reduce edge triggering)
	$(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); // average angle var initDeg = 0; // starting direction angle if($('#nmh-navicon').hasClass('Jnmh-onleft')){
	    	// If the floating ball is dragged to the left, the secondary menu will be displayed on the right li.css({transform: 'rotate(0deg)'});
	    	initDeg = 180;
	    }else{
	    	// By default, the floating ball is on the right and the secondary menu is on the left 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
	    });
	}

	//Mouse drag logo to move $(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 distanceX = e_down.pageX - positionDiv.left;
	    var distanceY = e_down.pageY - positionDiv.top + $(document).scrollTop();
		$(document).mousemove(diy_move);
		function diy_move(e_move){
			var x = e_move.pageX - distanceX;
	        var y = e_move.pageY - distanceY;

	        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> 

insert image description here

This is the end of this article about the implementation of the html sliding imitation floating ball menu effect. For more related html sliding imitation floating ball menu content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Sublime / vscode quick implementation of generating HTML code

>>:  How to pop up a temporary QQ dialog box to chat online without adding friends

Recommend

JavaScript implements mouse drag to adjust div size

This article shares the specific code of JavaScri...

HTML5+CSS3 coding standards

The Golden Rule No matter how many people are wor...

A friendly alternative to find in Linux (fd command)

The fd command provides a simple and straightforw...

Detailed explanation of mysql.user user table in Mysql

MySQL is a multi-user managed database that can a...

How to implement simple data monitoring with JS

Table of contents Overview first step Step 2 Why ...

Detailed explanation of vuex persistence in practical application of vue

Table of contents vuex persistence Summarize vuex...

Vue element implements table adding, deleting and modifying data

This article shares the specific code of vue elem...

TimePicker in element disables part of the time (disabled to minutes)

The project requirements are: select date and tim...

Vue3 gets the current routing address

Correct answer Using useRouter : // router path: ...

vue-cli configuration uses Vuex's full process record

Table of contents Preface Installation and Usage ...

Let's talk about the characteristics and isolation levels of MySQL transactions

The Internet is already saturated with articles o...

Learn the key knowledge that must be mastered in the Vue framework

1. What is Vue Vue is a progressive framework for...

5 Reasons Why Responsive Web Design Isn’t Worth It

This article is from Tom Ewer's Managewp blog,...

Vue basic instructions example graphic explanation

Table of contents 1. v-on directive 1. Basic usag...