Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<div class="block-card">
  <img src="https://picsum.photos/200">
  <span class="name">One</span>
  <span class="price">10</span>
  <span class="title">One number ...</span>
  <button id="btn-one">Показать анимацию</button>
</div>

<div class="block-card">
  <img src="https://picsum.photos/id/112/200">
  <span class="name">Two</span>
  <span class="price">110</span>
  <span class="title">Two number ...</span>
  <button id="btn-two">Показать анимацию</button>
</div>

<div class="block-card">
  <img src="https://picsum.photos/id/1043/200">
  <span class="name">Three</span>
  <span class="price">30</span>
  <span class="title">Three number ...</span>
  <button id="btn-three">Показать анимацию</button>
</div>

<div class="block-card">
  <img src="https://picsum.photos/id/227/200">
  <span class="name">Four</span>
  <span class="price">15</span>
  <span class="title">Four number ...</span>
  <button id="btn-four">Показать анимацию</button>
</div>

<div class="modal"></div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
body {
  margin: 0;  
}

img {
  max-width: 100%;
  height: auto;
}

span {
  display: block;
  margin: 5px 0;
  padding: 5px 0;
  border-radius: 3px;
  background-color: #6f7373;
  text-align: center;
  color: #fff;
}

span:nth-child(4) {
  margin-bottom: 12px;
}

button {
  display: block;
  margin: auto;
  padding: 10px 15px;
  border: 0;
  background-color: rgba(204, 204, 204, 0.40);
  color: #000;
  font-size: 15px;
  cursor: pointer;;
}

button:focus {
  outline: none;
}

.block-card, .modal {
  margin: 40px 0 0 40px;
}

.block-card {
  width: 200px;
  display: inline-block;
}

.modal {
  position: relative;
  width: 61%;
  height: 430px;
  text-align: center;
  background-color: #ccc;
}

.item {
  position: relative;
  top: 50px;
  left: -35%;
  max-width: 180px;
  text-align: center;
  transition: 0.8s ease;
}

.item-show {
  left: 10%;
}

.item button {
  padding: 10px 60px;
  border-radius: 5px;
  background-color: #b1b1b1;
  color: #fff;
}

              
            
!

JS

              
                const modal = $('.modal');

let item = [];

function saveItem() {
  localStorage.setItem("item-card", JSON.stringify(item));
}

$('button').on('click', function() {
  let $this = $(this);
  // let card = $('button').index($this);
  let img = $this.parent().find('img').attr('src');
  let name = $this.parent().find('.name').text();
  let price = $this.parent().find('.price').text();
  let title = $this.parent().find('.title').text();
  let id = $this.attr('id');
  
  let obj = {
    img: img, 
    name: name,
    price: price,
    title: title,
    id: id
  }
  
  item.push(obj);
  
  saveItem();
  showItem(id);
  
  // let Item = function(img, name, price, title) {
  //   this.img = img;
  //   this.name = name;
  //   this.price = price;
  //   this.title = title;
  //   console.log(img);
  // }
  
  // let obj = {
  //   img: img,
  //   name: "One",
  //   price: 150,
  //   title: 'One number ...'
  // }
  
  // let arr = [
  //   new Item(obj.img, obj.name, obj.price, obj.title),
  //   new Item(obj.img, obj.name, obj.price, obj.title),
  //   new Item(obj.img, obj.name, obj.price, obj.title),
  //   new Item(obj.img, obj.name, obj.price, obj.title)
  // ];
});

function showItem(id) {
  item = JSON.parse(localStorage.getItem("item-card"));
  if (item !== null) {
   for (let i = 0; i < item.length; i++) {
      $('#' + item[i].id).prop("disabled", true).text('Добавлено');
    } 
  } else if (item === null) {
    item = []
  }
 
  let out = "";
  for (let i in item) {
    out += '<div class="item">'
    out += '<img src="' + item[i].img + '" alt="picture">'
    out += '<span>' + item[i].name + '</span>'
    out += '<span>' + item[i].price + '</span>'
    out += '<span>' + item[i].title + '</span>'
    out += '<button class="remove-item" id="' + item[i].id + '">Удалить</button>'
    out += '</div>';
    }
  
    modal.html(out);
  
    setTimeout(function() {
      $('.item').addClass('item-show');
	  }, 80);
}

function removeItem(id) {
  item = item.filter(function(e) { return e.id !== id});
  $('#' + id).prop("disabled", false).text('Показать анимацию');
  saveItem();
}

$(modal).on("click", ".remove-item", function() {
  let id = $(this).attr('id');
  // let remove = $(this).parent();
  // remove.removeClass('item-show');
  removeItem(id);
  showItem();
});

showItem();
              
            
!
999px

Console