// the math function that places the bubbles on a circle arch
jQuery.fn.semiCircle = function(cx, cy, radius, radiusY, startDegrees, endDegrees) {
if (radiusY === undefined) radiusY = radius;
if (startDegrees === undefined) startDegrees = 0;
if (endDegrees === undefined) endDegrees = 360;
var startRadians = startDegrees * Math.PI / 180,
endRadians = endDegrees * Math.PI / 180,
stepRadians = (endRadians - startRadians) / (this.length - 1);
return this.each(function(i) {
var a = i * stepRadians + startRadians,
x = Math.cos(a) * radius + cx,
y = Math.sin(a) * radiusY + cy;
$(this).css({
left: x + 'px',
top: y + 'px'
});
});
};
// store needed selectors
let floatTrigger = $('.float-trigger');
let floatingEl = $('.floating-item');
let floatParent = $('.share-items');
floatTrigger.on('click', function() {
// get X and Y position of the clicked pin
let trigPosX = $(this).position().left + $(this).width() / 2;
let trigPosY = $(this).position().top + $(this).height() / 2;
//set the position of the standalone floating buttons in the center of the clicked icon
floatParent.css({
top: trigPosY + "px",
left: trigPosX + "px"
});
//change the icon inside the trigger
$(this).find('.fa').toggleClass('fa-bars fa-times');
if (floatParent.hasClass("opened")) {
floatingEl.semiCircle(0, 0, 0, 0, 0, 0); //reset icons positions to 0
floatParent.removeClass("opened").addClass("closing"); // close the floating items with an animation
setTimeout(function() {
floatParent.removeClass("closing");
}, 200);
//get pos of new clicked element
} else {
floatingEl.semiCircle(0, 0, 100, 100, 0, 90);
floatParent.addClass("opened").removeClass("closing");
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.