How To Place Buttons Around A Circle with HTML5 and CSS 3? - html

I want to arrange 4 buttons (or bootstrap tabs,doesn't matter) around a circle and load a content in the middle of that circle,something like this:
How can i do that?

you could use a small bit of jquery to load your center circle with the text you want.
$(document).ready(function() {
$('.quart').click(function() {
var ind = $(this).index();
switch (ind) {
case 0:
var tex = "div 1";
break;
case 1:
var tex = "div 2";
break;
case 2:
var tex = "div 3";
break;
case 3:
var tex = "div 4";
break;
}
$('.center').text(tex);
});
});
.wrap {
height: 300px;
width: 300px;
border-radius: 50%;
position: relative;
overflow: hidden;
}
.quart {
position: absolute;
height: 50%;
width: 50%;
background: tomato;
transition: all 0.4s;
}
.quart:first-child {
top: 0;
left: 0;
}
.quart:nth-child(2) {
top: 0;
left: 50%;
}
.quart:nth-child(3) {
top: 50%;
left: 0;
}
.quart:nth-child(4) {
top: 50%;
left: 50%;
}
.center {
height: 80%;
width: 80%;
position: absolute;
top: 10%;
left: 10%;
background: lightgray;
border-radius: 50%;
text-align: center;
line-height: 160px;
}
.quart:hover {
background: dimgray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrap">
<div class="quart"></div>
<div class="quart"></div>
<div class="quart"></div>
<div class="quart"></div>
<div class="center">Click My non-existent Corners!</div>
</div>
This probably won't be as efficient as an svg solution, but colud be altered to your needs.

You can use the HTML <map> tag - more info

Related

fadeout() with stop(true, true) and delay() in JQuery seems not working good

Why this animation with fadeout does not works good.
It has to generate a random string, put it in div#a p, wait 1500 milliseconds, do a fadeout() and then delete the html by using a promise()
$(document).on("click","#click",function() {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < 10; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
$("#a p").html(result);
$("#a").stop(true, true).show().delay(1500).fadeOut('slow', function() { $(this).stop(true, true).promise().done(function() { $(this).find("p").html(''); }) });
});
div {
display: flex;
align-items: center;
}
div p {
width: 100%;
text-align: center;
}
div#click {
background-color: green;
color: white;
position: fixed;
top: 0px;
right: 50%;
width: 100px;
height: 100px;
cursor: pointer;
}
div#a {
background-color: red;
color: black;
position: fixed;
top: 100px;
right: 50%;
width: 100px;
height: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="click"><p>CLICK THIS</p></div>
<div id="a"><p></p></div>
But does not works good as expected.
Sometimes times are respected, sometimes not. And it can happen also that the html disappears.
There's someone better then me that knows why and can solve this?

Bind the index and ionic card together - ionic

I am doing a project on ionic. It is a quiz type app. I have scrollable div on the top which contains all the question numbers. Below that I have cards where questions are appearing. The screenshot is below :
The cards have swipable feature in it that users can swipe the cards to and fro.
My requirement is when the user selects a particular question from the top question number panel, corresponding questions should show and the selected question should be highlighted. Also when the user swipes the cards, the selection of the question numbers in the top should also change.
I created a circle using css for the above panel and using ng-repeat, I am repeating the question numbers. I added a ng-click option on the question number and passing the index. So that I can show the corresponding question. By using this I am able to bind the both panels in one way. I need to bind it reverse too. So that when user swipes the card, the question number should change.
Also I need to highlight a particular item in ng-repeat to show that that is selected. I tried :hover property in css, it somehow highlighting the selected item but not as good as expected.
Here is my code:
angular.module('quiz', ['ionic'])
.controller('QuizController', function($scope) {
$scope.nodes = [{
count: 1,
disabled: false
}, {
count: 2,
disabled: false
}, {
count: 3,
disabled: false
}, {
count: 4,
disabled: false
}, {
count: 5,
disabled: true
}];
$scope.goToQuestionNumber = function(index) {
console.log('goToQuestionNumber: ', index);
$scope.currentQuestion = index;
$scope.act_type = $scope.quiz.clues[$scope.currentQuestion].act_type;
$scope.isActive = $scope.nodes[index];
changeTemplate();
}
$scope.next = function() {
if ($scope.currentQuestion != ($scope.nodes.length - 1)) {
$scope.currentQuestion++;
$scope.currentTry = 1;
$scope.act_type = $scope.quiz.clues[$scope.currentQuestion].act_type;
$scope.failureResult = false;
changeTemplate();
}
}
$scope.prev = function() {
if ($scope.currentQuestion != 0) {
$scope.additionalActivity = false;
$scope.addtionalQuestionAvailability = false;
console.log('Left swipe');
$scope.currentQuestion = $scope.currentQuestion - 1;
$scope.currentTry = 1;
$scope.act_type = $scope.quiz.clues[$scope.currentQuestion].act_type;
$scope.failureResult = false;
changeTemplate();
}
}
})
.events {
position: relative;
}
.event,
span .event,
.event span {
content: "";
float: left;
position: relative;
padding: 3%;
margin: 0% 2% 0% 2%;
border-radius: 50%;
background-color: lightgrey;
border: 3px solid darkgray;
top: 15%;
left: 2%;
font-size: 15px;
z-index: 1;
text-align: center;
line-height: 150%;
color: hotpink;
}
.slider-column {
position: relative;
display: flex;
flex: 0 0 30%;
}
.slider-column::after {
content: '';
height: 3px;
width: 100%;
background-color: #66a3ff;
position: absolute;
top: 45%;
z-index: -5;
margin-left: 0%;
border-radius: 1% 1% 1% 1%;
padding: 1%;
}
.slider-column:last-child:after {
content: '';
height: 2%;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
}
/*.event::after{
content:'';
height:3px;
width:170%;
background-color:#6d6dff;
position: absolute;
top: 45%;
z-index: -5;
margin-left: 55%;
border-radius: 1% 1% 1% 1%;
padding: 1%;
}*/
.event::before {
content: '';
height: 5px;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
z-index: -5;
padding-left: 10%;
}
.events:first-child:before {
content: '';
height: 5px;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
}
.events:last-child-1:after {
content: '';
height: 5px;
width: 100%;
background-color: transparent;
position: absolute;
top: 30%;
}
.timeline-text {
z-index: 4;
top: 0;
bottom: 5px;
}
.enabled-event {
background: red;
}
.event:hover {
border-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ionic/1.3.0/js/ionic.bundle.min.js"></script>
<ion-content ng-app="quiz" ng-controller="QuizController">
<div style="padding-top:10px;padding-left:5px;">
<label class="hamburger" style="float:left">Score:{{totalPoints}} pts</label>
<button style="float:right" class="button button-clear button-small bonus-button" ng-click="bonus()">Try Bonus</button>
</div>
<br>
<br>
<ion-scroll direction="x" class="timeline-scroll">
<div class="timeline">
<div class="events row">
<div class="slider-column" ng-repeat="count in nodes">
<span class="event " ng-click="goToQuestionNumber($index)" ng-if="!count.disabled">
{{count.count}}/{{nodes.length}}
</span>
<span class="event" ng-click="goToQuestionNumber($index)" ng-if="count.disabled">
{{count.count}}/{{nodes.length}}
<!-- </span> -->
</div>
</div>
</div>
</ion-scroll>
<br>
<br>
<div ng-include="currentClueTemplate" ng-swipe-right="prev()" ng-swipe-left="next()" class="question-card"></div>
</ion-content>
Can anyone help me ?

Show hidden content when hovering a div

How can i create this animation on this website:
https://www.beepi.com/
When you hover on the blue and green circle makes that animation, i want to do the same with this design:
What should i use and do it? Any tutorials, guides, something ? That i can see and be capable to implement it on my site.
I tried to make that effect. Here's what I've done:DEMO JsFiddle.
function js1(x) {
x.style.animation = "anime 5s";
}
function js2(x) {
x.style.animation = "anime1 5s";
}
#first {
position: absolute;
float: left;
width: 100px;
height: 100px;
background-color: black;
top: 200px
}
#sec {
position: relative;
float: right;
width: 100px;
height: 100px;
background-color: black;
top: 200px
}
#Keyframes anime {
from {
left: 0;
}
to {
left: -400px;
}
}
#Keyframes anime1 {
from {
left: 0;
}
to {
left: 400px;
}
}
<div id="first" onmouseenter="js1(this)"></div>
<div id="sec" onmouseenter="js2(this)"></div>
Fell free to use the code. Now You must only resolve the problem with scroll(the page must go left-I don't know how to do that but I'll try).
I used javascript and onmouseenter to create the hover part. You can read about onmouseenter here and about #Keyframes here.

Background position seems to be inaccurate

I've an image and I have put a mask over it.
The mask is divided into 3 equal parts. Each part has the same image as its background.
Each part has 1/3rd portion of image. I am changing background position of each part, so the masks (collectively) look exactly like the image.
Everything works great, but 2nd part has some issue in background-image, and it looks few pixels shifted to the right.
I need to remove that shifting.
Demo
HTML:
<div id="wrapper">
<div id="main">
<img src="http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg" />
</div>
<div id="mask">
<div class="part part1"></div>
<div class="part part2"></div>
<div class="part part3"></div>
</div>
</div>
<br>
<button id="switcher" class="main">Put mask on top</button>
CSS:
img {
width: 100%;
height: 100%;
}
#wrapper {
position: relative;
width: 390px;
height: 300px;
}
#main {
z-index: 2;
}
#mask {
z-index: 1;
}
#main, #mask, .part {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.part {
background-image: url('http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg');
background-size: 390px 300px;
width: 130px;
}
.part2 {
background-position: -130px 0;
left: 130px;
}
.part3 {
background-position: -260px 0;
left: 260px;
}
JS:
$('#switcher').click(function () {
if ($(this).hasClass('main')) {
$(this).html('Put mask on top').removeClass('main');
$('#main').css({
zIndex: 1
});
$('#mask').css({
zIndex: 2
});
} else {
$(this).html('Put main on top').addClass('main')
$('#main').css({
zIndex: 2
});
$('#mask').css({
zIndex: 1
});
}
});
It is because you are using image of dimension 425x318 and resizing background to 390x300, so image gets distorted as aspect ratios of them do not match.
Check updated demo, here I have used wrapper dimension of same size as of image, i.e. 425x318.
JS Fiddle Demo
Update in code:
CSS
Remove background-size from .part and change #wrapper width, height.
img {
width: 100%;
height: 100%;
}
#wrapper {
position: relative;
width: 425px;
height: 318px;
}
#main {
z-index: 2;
}
#mask {
z-index: 1;
}
#main, #mask, .part {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.part {
background-image: url('http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg');
/*background-size: 390px 300px;*/
width: 130px;
}
.part1 {
background-position: 0 0;
left: 0;
}
.part2 {
background-position: -130px 0;
left: 130px;
}
.part3 {
background-position: -260px 0;
left: 260px;
}
UPDATE:
As you mentioned in comment that Image is not in control, background-size properties contain and cover also not working.
The only feasible option seems to get the image dimensions by some method (javascript OR server side code) and dynamically set the #wrapper dimensions to match image dimensions.
JavaScript Code: (For getting image dimensions and set Wrapper dimensions accordingly)
http://jsfiddle.net/8au8nhe5/19/
$(document).ready(function() {
var myImage = new Image();
myImage.src = "http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg";
$(myImage).on('load', function() {
console.log('My width is: ', this.naturalWidth);
console.log('My height is: ', this.naturalHeight);
$("#wrapper").css({"width": this.naturalWidth + "px", "height": this.naturalHeight + "px"});
});
});
For Reference:
http://davidwalsh.name/get-image-dimensions
https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement
As pointed out by Dharmang, cause of the issue was aspect ratio of image. And, it was not possible to fix, without changing the #wrapper dimension, or the image itself.
I've found a workaround, but using img tag, instead of background-image, so that I can distort the aspect ratio of images of mask div, in equal amount, as it is destroyed by the 'real image'.
$('#switcher').click(function () {
if ($(this).hasClass('main')) {
$(this).html('Put mask on top').removeClass('main');
$('#main').css({
zIndex: 1
});
$('#mask').css({
zIndex: 2
});
} else {
$(this).html('Put main on top').addClass('main')
$('#main').css({
zIndex: 2
});
$('#mask').css({
zIndex: 1
});
}
});
img {
width: 100%;
height: 100%;
}
#wrapper {
position: relative;
width: 390px;
height: 300px;
}
#main {
z-index: 2;
}
#mask {
z-index: 1;
}
#main, #mask, .part {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.part {
width: 130px;
}
.part img {
margin-left: 0;
width: 390px;
height: 300px;
}
.part2 {
left: 130px;
}
.part2 img {
margin-left: -130px;
}
.part3 {
left: 260px;
}
.part3 img {
margin-left: -260px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">
<div id="main">
<img src="http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg" />
</div>
<div id="mask">
<div class="part part1"><img src="http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg" /></div>
<div class="part part2"><img src="http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg" /></div>
<div class="part part3"><img src="http://images.all-free-download.com/images/graphiclarge/grasshopperpraying_mantis_195444.jpg" /></div>
</div>
</div>
<br>
<button id="switcher" class="main">Put mask on top</button>

Image over image, middle position

This is my CSS class:
.overitem {
position: relative;
background: url(images/bg.png) no-repeat;
width:83px;
height: 83px;
}
.sit {
position: absolute;
top: 50%;
left: 50%;
}
My HTML :
<div class="overitem"><img src="/images/vcs.png" class="sit"/></div>
The problem is that I can not make the from the img tag, in a middle of the background of overitem class. What should I do, to make it appear in the middle of the bg.png image?
Since the .sit class has to have a fixed width and height (because its an image), you can use the following method:
.sit {
position: absolute;
top: 50%;
left: 50%;
width: 500px;
height: 500px;
margin-top: -250px; /* Half the height */
margin-left: -250px; /* Half the width */
}
Source: http://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/
you can set margins as
1/2(width of "overitem" minus width of "sit") and
1/2(height of "overitem" height width of "sit")
or try this:
.sit {
position: absolute;
top: 50%;
left: 50%;
margin-left: -(HALF_OF_WIDTH_OF_IMAGE);
margin-top: -(HALF_OF_HEIGHT_OF_IMAGE);
}
In the .sit class you need to have:
margin-left: -(half of width);
margin-top: -(half of height);
An alternative option is:
.overitem {
position: relative;
background: url(images/bg.png) no-repeat;
width:83px;
height: 83px;
line-height: 83px;
}
.sit {
vertical-align: middle;
}
Try this:
elems = document.getElementsByClassName('sit');
for( i = 0, j = elems.length; i < j; i++){
elems[ i ].style.marginLeft = ( elems[ i ].parentNode.offsetWidth - elems[ i ].offsetWidth ) / 2;
elems[ i ].style.marginTop = ( elems[ i ].parentNode.offsetHeight - elems[ i ].offsetHeight ) / 2;
}