Translate

AlbanianArabicEnglishFrenchGermanItalianRussianSpanish

Javascript on checked box clone this div, on unchecked remove this div

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div class="avclone">
<div class="column">
<div class="columns">
<label class="AvGamesContainer">
<input type="checkbox" name="AvGamesContainer" class="AvGamesCheckBox" checked/>
<span class="AvGamesCheckmark"></span>
</label>
<a href="https://games.softgames.com/games/aquablitz-2/gamesites/7665/" data-path><img src="https://d1bjj4kazoovdg.cloudfront.net/assets/games/aquablitz-2/teaser.jpg?p=pub-15088-15357" title="Aqua Blitz 2"></a>
</div>
</div>
<div class="column">
<div class="columns">
<label class="AvGamesContainer">
<input type="checkbox" name="AvGamesContainer" class="AvGamesCheckBox" />
<span class="AvGamesCheckmark"></span>
</label>
<a href="https://games.softgames.com/games/daily-sudoku/gamesites/7665/" data-path><img src="https://d1bjj4kazoovdg.cloudfront.net/assets/games/daily-sudoku/teaser.jpg?p=pub-15088-15357" title="Daily Sudoku"></a>
</div>
</div>
</div>
<div id="favorite"></div>

console.clear();
(function($) {
$.fn.filterByData = function(prop, val) {
return this.filter(
function() {
return $(this).data(prop) == val;
}
);
}
})(window.jQuery);

console.log("Orgchecked", $(".avclone").find('.AvGamesCheckBox:checked').length);

function onClickAvGamesCheckBox(event) {
console.log("checked", $(".avclone").find('.AvGamesCheckBox:checked').length);
var arr = $(".avclone").find('.AvGamesCheckBox').map(function(index, element) {
console.log("isChecked", index, $(element).prop('checked'));
return {
"index": index,
checkvalue: $(element).prop('checked')
};
}).get();
localStorage.setItem("favchecked", JSON.stringify(arr));
}

$(function() {
//add some data
var checks = $(".avclone").find('.AvGamesCheckBox');
checks.each(function(index, element) {
$(this).closest('.column').data("checkindex", index);
});
var arr = JSON.parse(localStorage.getItem('favchecked')) || [];
arr.forEach(function(stored, i) {
console.log("s", stored, "index", stored.index, "evalue", stored.checkvalue)
checks.eq(stored.index).prop('checked', stored.checkvalue);
});
checks.trigger("change");
});

//* Clone script
$(".avclone, #favorite").on('change', '.AvGamesCheckBox', function(event) {

var checkContainer = $(this).closest('.column');
var checkIndex = checkContainer.data("checkindex");
var matcher = $("#favorite").find(".column").filterByData("checkindex", checkIndex);
if (this.checked && !matcher.length) {
checkContainer.clone(true).appendTo("#favorite");
} else {
var org = $(".avclone").find('.AvGamesCheckBox').eq(checkIndex);
org.prop("checked",this.checked);
org.trigger('mycustomclick');
matcher.remove();
}
});
$(".avclone").on('click mycustomclick', '.AvGamesCheckBox', onClickAvGamesCheckBox);

* {
box-sizing: border-box;
padding: 5px;
}

.AvGamesContainer {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.AvGamesContainer input {
position: absolute;
opacity: 0;
display: none;
visibility: hidden;
cursor: pointer;
height: 0;
width: 0;
}

.AvGamesCheckmark {
position: absolute;
top: 26px;
right: 0;
height: 25px;
width: 25px;
padding: 3px !important;
background-color: #fff;
background-image: url("https://i.ibb.co/Yyp3QTL/addstar.png");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
-webkit-border-top-right-radius: 5px;
-webkit-border-bottom-left-radius: 8px;
-moz-border-radius-topright: 5px;
-moz-border-radius-bottomleft: 8px;
border-top-right-radius: 5px;
border-bottom-left-radius: 8px;
z-index: 5;
}

.AvGamesContainer input:checked~.AvGamesCheckmark {
background-color: #fff;
color: yellow !important;
background-image: url("https://i.ibb.co/0J7XxyK/favstar.png");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}

.AvGamesContainer:hover input~.AvGamesCheckmark {
background-color: #fff;
}

.AvGamesCheckmark:after {
content: "";
position: absolute;
display: none;
}

.AvGamesContainer input:checked~.AvGamesCheckmark:after {
display: none;
}

.AvGamesContainer .AvGamesCheckmark:after {
display: none;
}

img {
width: 100%;
height: auto;
background: #fff;
border-radius: 10px;
-webkit-box-shadow: 0px 1px 5px 2px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 1px 5px 2px rgba(0, 0, 0, 0.75);
box-shadow: 0px 1px 5px 2px rgba(0, 0, 0, 0.75);
transition: all 0.5s ease-in-out 0s;
z-index: 4;
}

img:hover {
-webkit-box-shadow: 0px 1px 5px 2px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 1px 5px 2px rgba(0, 0, 0, 0.75);
box-shadow: 0px 1px 5px 2px rgba(0, 0, 0, 0.75);
-webkit-filter: saturate(150%);
}

.column {
float: left;
width: 50%;
padding: 5px;
height: auto;
}

.columns {
position: relative;
border-radius: 10px;
text-align: center;
width: 99%;
margin: 0 auto;
padding: 5px;
}

.row:after {
content: "";
display: table;
clear: both;
}

 

Leave a Reply

inGolin.com © 2018 Terms of Agreement