14 kwi 2015

Stworzenie ciągu DD-MM-YYYY z obiektu DATE

Poniższy fragment kodu pokazuje, jak uzyskać sformatowany ciąg DD-MM-YYYY z obiektu Date.

var date = new Date();
 
var yyyy = date.getFullYear().toString();
var mm = (date.getMonth()+1).toString();
var dd  = date.getDate().toString();
 
var mmChars = mm.split('');
var ddChars = dd.split('');
 
var currentDay = (ddChars[1]?dd:"0"+ddChars[0]) + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + yyyy;

console.log(currentDay);
2 mar 2015

Trochę animacji w CSS3 - kafelki

Animacja "kafelków" w css3

Trochę css

.box-flip {
  width: 999px;
  height: 390px;

}

.box-flip .front {
  line-height: 194px;
  text-align: center;
  font-weight: bold;
  font-size: 40px;
  font-family: Helvetica, Arial, Verdana, sans-serif;
  color: #c6001f;
  border: 1px solid;

}

.box-flip .item {
  float: left;
  cursor: pointer;
}

.box-flip .item .row-item {
  -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  -o-transform-style: preserve-3d;
  -ms-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transition: 0.6s -webkit-transform;
  -moz-transition: 0.6s -moz-transform;
  -o-transition: 0.6s -o-transform;
  -ms-transition: 0.6s -o-transform;
  transition: 0.6s transform;
  position: relative;
}

.box-flip .item:hover .row-item {
  -webkit-transform: rotateY(.5turn);
  -moz-transform: rotateY(.5turn);
  -o-transform: rotateY(.5turn);
  -ms-transform: rotateY(.5turn);
  transform: rotateY(.5turn);
}

.box-flip .item .row-item>.back {
  overflow: hidden;
  opacity: 0;
  -webkit-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -moz-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -o-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -ms-transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  transform: scale(0.4) rotateY(0.5turn) translateZ(1px);
  -webkit-transition: 0.4s .075s opacity, 0.2s -webkit-transform;
  -moz-transition: 0.4s .075s opacity, 0.2s -moz-transform;
  -o-transition: 0.4s .075s opacity, 0.2s -o-transform;
  -ms-transition: 0.4s .075s opacity, 0.2s -ms-transform;
  transition: 0.4s .075s opacity, 0.2s transform;
  display: block;
}

.box-flip .item .row-item>.back {
  display: none\9;
}

.box-flip .item:hover .row-item>.back {
  overflow: visible;
  opacity: 1;
  -webkit-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  -moz-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  -o-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  -ms-transform: scale(1) rotateY(0.5turn) translateZ(1px);
  transform: scale(1) rotateY(0.5turn) translateZ(1px);
}

.box-flip .item:hover .row-item>.back {
  display: block\9;
}

.box-flip .item {
  -webkit-perspective: 1200px;
  -moz-perspective: 1200px;
  -o-perspective: 1200px;
  -ms-perspective: 1200px;
  perspective: 1200px;
  overflow: visible;
}

.box-flip div.back {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  background: #f7732f;
  z-index: 2;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
  line-height: 194px;
  text-align: center;
}

.box-flip .box-a {
  width: 333px;
  height: 195px;
  margin-right: 2px;
  margin-bottom: 2px;
}

.box-flip .box-a .back {
  width: 333px;
  height: 195px;
}

.box-flip .box-b {
  width: 664px;
  height: 195px;
  margin-bottom: 2px;
}

.box-flip .box-b .back {
  width: 664px;
  height: 195px;
}

.box-flip .box-c {
  width: 333px;
  height: 194px;
  margin-right: 2px;
}

.box-flip .box-c .back {
  width: 333px;
  height: 194px;
}

.box-flip .box-d {
  width: 331px;
  height: 194px;
  margin-right: 2px;
}

.box-flip .box-d .back {
  width: 331px;
  height: 194px;
}

.box-flip .box-e {
  width: 331px;
  height: 194px;
}

.box-flip .box-e .back {
  width: 331px;
  height: 194px;
}
8 lip 2014

Sortowanie polskich znaków w javascript

function MySort(alphabet) {
  return function (a, b) {
    const index_a = alphabet.indexOf(a[0]);
    const index_b = alphabet.indexOf(b[0]);

    if (index_a === index_b) {
      if (a < b) {
        return -1;
      }
      if (a > b) {
        return 1;
      }
      return 0;
    }
    return index_a - index_b;
  };
}

const items = ['świat', '1', 'ł', 'k', 'ą', '*sdf', '!', '!sdf', '@asdf', 'łódź', '_asd', '.sadf', '(sadf', ')sadf', '#sadf', '^asdf', '&asdf', '%asdf', '-sadf', '=sadf', '+sadf', '-sdf', 'sef', 'brocka'];

const sorter = MySort(
  '*!@_.()#^&%-=+01234567989aąbcćdeęfghijklłmnńoóprsśtuwyzźż'
);

console.log(items.sort(sorter));

W wersji z ES6 można to zrobić o wiele prościej:

items.sort((a, b) => a.localeCompare(b);

Polecam zapoznać się localeCompare, ma kilka przydatnych opcji.

5 gru 2013

Dzisiejszy dzień.

var browser = function() {
  var days = ['Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'];
  var today = new Date();
  var msg = 'Dzisiaj jest: ' + days[today.getDay()] + ', ' + today.getDate();
  console.log(msg);
}

Wywołanie oczywiście

browser();