Skip to content

Commit

Permalink
Solucionado o desafio unico da aula 015
Browse files Browse the repository at this point in the history
  • Loading branch information
eudes-silva committed Jan 14, 2019
1 parent ab3d495 commit d6a5a50
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 63 deletions.
6 changes: 6 additions & 0 deletions Desafios aula 015/desafiounico.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Desafio Único Collabcode aula 015

- Descrição:
- Utilizando um evento de clique faça o preenchimento das estrelas. Se estiver preenchida, ao clicar deve sumir o preenchimento, e caso esteja vazia, ao clicar, seja preenchida com a cor.
- Observação para este desafio:
Caso clique na terceira estrela, a segunda e a primeira tambem devem ser preenchidas, e caso clique na primeira as seguintes devem desativar o preenchimento.
Binary file modified css/img/heart-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions css/info-product.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
left: 0;
z-index: -1;
background: url(img/heart-active.png) 0 0 no-repeat;
-webkit-transform: scale(0.9);
transform: scale(0.9);
-webkit-transform: scale(1);
transform: scale(1);
}

.info-product > .-active:hover{
Expand Down
61 changes: 35 additions & 26 deletions css/rating-stars.css
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
.stars{
width: 270px;
display: inline-block;
position: relative;
right:40px;
float:left;
margin-top:0;
margin-bottom:20px;
position:relative;
right:88px;
}

.star{

label.star {
width:25px;
height: 25px;
float: right;
padding: 10px;
font-size: 36px;
color: #000;
font-size: 2rem;
padding: 0 2px;
display: inline-block;
position: relative;
font-family: FontAwesome;
transition: all .25s;
margin-bottom: 25px;
transition: all .2s;
}

.star::before{
content: '\f006';
label.star:hover{
cursor: pointer;

}
.star:hover::before{
transform: rotate(-15deg) scale(1.3);
color: #000;

label.star.star-1{
padding-left:0;
margin-left:0;
}
.star.rated::before{
content: '\f005';

label.star {
display: inline-block;
position: relative;
font-family: FontAwesome;
}

label.star::before {
content: "\f006";
}

.star.rated:hover{
label.star.-active::before{
content:"\f005";
}

label.star.-active:hover{
transform: rotate(-15deg) scale(1.3);
}



@media (max-width:1320px){
.stars{
float:left;
margin-right:10px;
}
}
Expand All @@ -45,8 +59,3 @@
}
}

@media(max-width:340px){
.stars{
width:100%;
}
}
14 changes: 7 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ <h1 class="title">logo</h1>
<dd class="heart -active">
<img class="heart-image" src="img/heart.png" alt="Like!">
</dd>
<div class="stars" data-rating="3">
<span class="star">&nbsp;</span>
<span class="star">&nbsp;</span>
<span class="star">&nbsp;</span>
<span class="star">&nbsp;</span>
<span class="star">&nbsp;</span>
</div>
<ol class="stars">
<label class="star star-5" for="star-5"></label>
<label class="star star-4" for="star-4"></label>
<label class="star star-3" for="star-3"></label>
<label class="star star-2" for="star-2"></label>
<label class="star star-1" for="star-1"></label>
</ol>
<dd class="info-body -number">4.0 (97)</dd>
<dd class="info-body"><strong class="contrast">Frete</strong> C$ 108</dd>
<dd class="info-body"><strong class="contrast">Preço</strong> C$ 348</dd>
Expand Down
2 changes: 1 addition & 1 deletion js/info-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function handleClick() {
$heart.classList.add("-active");
}*/

$heart.classList.toggle("-active");
this.classList.toggle("-active");

}

Expand Down
81 changes: 54 additions & 27 deletions js/rating-stars.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,64 @@
document.addEventListener('DOMContentLoaded', function(){
addListeners();
setRating();
});

function addListeners(){
var stars = document.querySelectorAll('.star');
[].forEach.call(stars, function(star, index){
star.addEventListener('click', (function(idx){
console.log('adding rating on', index);
document.querySelector('.stars').setAttribute('data-rating', idx + 1);
console.log('Rating is now', idx+1);
setRating();
}).bind(window,index) );
const $stars = document.querySelectorAll(".star");
const $starsRemove = document.querySelectorAll(".star");
const lastIndex = $stars.length-1;

$stars[0].addEventListener("click", lastStar);
$stars[1].addEventListener("click", fourthStar);
$stars[2].addEventListener("click", thirdStar)
$stars[3].addEventListener("click", secondStar);
$stars[lastIndex].addEventListener("click", firstStar);

function lastStar() {
$stars.forEach(function($star, key){
console.log($star, key);
$star.classList.add("-active");
});
}

function fourthStar() {
$stars.forEach(function($star, key){
console.log($star, key);
if(key>0){
$star.classList.add("-active");
}
$starsRemove[0].classList.remove("-active");
});

}

function setRating(){
var stars = document.querySelectorAll('.star');
var rating = parseInt( document.querySelector('.stars').getAttribute('data-rating') );
[].forEach.call(stars, function(star, index){
if(rating > index){
star.classList.add('rated');
console.log('added rated on', index );
}else{
star.classList.remove('rated');
console.log('removed rated on', index );
function thirdStar() {
$stars.forEach(function($star, key){
console.log($star, key);
if(key>1){
$star.classList.add("-active");
}
$starsRemove[1].classList.remove("-active");
$starsRemove[0].classList.remove("-active");
});
}



function secondStar() {
$stars.forEach(function($star, key){
console.log($star, key);
if(key>2){
$star.classList.add("-active");
}
$starsRemove[2].classList.remove("-active");
$starsRemove[1].classList.remove("-active");
$starsRemove[0].classList.remove("-active");
});
}

function firstStar() {
$stars.forEach(function($star, key){
console.log($star, key);
if(key>3){
$star.classList.add("-active");
}
$starsRemove[3].classList.remove("-active");
$starsRemove[2].classList.remove("-active");
$starsRemove[1].classList.remove("-active");
$starsRemove[0].classList.remove("-active");
});
}


0 comments on commit d6a5a50

Please sign in to comment.