Created
May 28, 2014 03:05
-
-
Save Rplus/c7ae873f58c15cec12f1 to your computer and use it in GitHub Desktop.
A Pen by Rplus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- books1 = [["Book A", 150], ["Book B", 99]] | |
- books2 = [["Book C", 50], ["Book D", 399]] | |
- books = [books1, books2] | |
mixin book(name, price) | |
dl | |
dt.books__name #{name} | |
dd.books__pricw NT #{price} $ | |
dd.books__cover | |
img.books__cover__img(data-src="//fakeimg.pl/150x100/?text=#{name}") | |
ul.books | |
each cate, i in books | |
li.books__category | |
span.books__category__name category-#{i} | |
each book in books[i] | |
+book(book[0], book[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var imgLoadedClass = 'is-img-loaded'; | |
var loadLazyImage = function (imgs) { | |
$.each(imgs, function replaceSrc() { | |
var _img = $(this); | |
_img.prop('src', _img.attr('data-src')) | |
}) | |
}; | |
$('.books').on('click', '.books__category__name', function() { | |
var _this = $(this), | |
_category = _this.parent(); | |
_category.toggleClass('active'); | |
if (!_this.hasClass(imgLoadedClass)) { | |
loadLazyImage(_category.find('.books__cover__img')); | |
_category.addClass(imgLoadedClass); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.books__category { | |
dl { | |
margin-top: 0; | |
margin-bottom: 0; | |
overflow: hidden; | |
height: 0; | |
/* display: none; */ | |
} | |
&.active dl { | |
height: auto; | |
/* display: block; */ | |
} | |
} | |
.books__category__name { | |
background-color: #eec; | |
cursor: pointer; | |
} | |
.books__cover__img { | |
transition: opacity .5s; | |
opacity: 0; | |
.active & { | |
opacity: 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment