Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNuno Nunes
8,849 PointsHow to do divs filtering and loading?
Good afternoon,
I am trying to create a list of divs that have a link to a video. Each div has a different description on top and there are "too many" divs to present all at once on the screen.
I want to have a filter to reduce the amount of "interesting" divs to the user and load them while the user scroll the page.
Something similar to this: http://wodwell.com/wods/
I am completely lost...would you please give me some tips?
22 Answers
Kallil Belmonte
35,561 PointsHi Nuno, Some plugins achieve that, take a look:
https://terwanerik.github.io/ScrollTrigger/
Kallil Belmonte
35,561 PointsOf course, sorry...
At my notepad's links I have the following: https://github.com/jiren/filter.js/tree/master -Demo: http://jiren.github.io/filter.js/index.html
Kallil Belmonte
35,561 PointsHi Nuno,
Some of the resources are jQuery plugins, to learn how to implement them I suggest this course: Using jQuery Plugins
Nuno Nunes
8,849 PointsHi,
Thank you for the plugins. I'll have a look.
What about the filter system and how should I store all the divs. Can you help me with that?
Nuno Nunes
8,849 PointsHi!
Thank you for the links. That's exactly what I need. I didn't understand straight away how to apply them but I will study them later and do some trials.
Thank you!
Nuno Nunes
8,849 PointsThank you! I will watch it :)
Nuno Nunes
8,849 PointsHi again :)
I'm looking into the filter that you show me: https://github.com/jiren/filter.js/tree/master
It look different from the jquery plugins and am I in trouble to implement it...
First, my data is in this format:
<div class="className" data-collapse="accordion persist">
<h2>Title of Item</h2>
<ul>
<li>Item type</li>
<li><div class="subItem-li">
<p>subItem 1</p>
<a href="" title=""><img src="img/play.png" alt=""/></a>
</div></li>
<li><div class="subItem-li">
<p>subItem 2</p>
<a href="" title=""><img src="img/play.png" alt=""/></a>
</div></li>
</ul>
</div>
So, there is a title. and then a list. Each list item contains text on the left and a image with a link on the right.
I want to filter them by Item type and subitem using checkboxes.
Also, in the external examples I noticed that they use the class="fjs_item" but I don't see any reference to it in the documentation.
Do I need to change my divs to be like the VIEW in the documentation???
Create a template using the script with all those divs classes and tables to present information??? That doesn't sound correct to me...
Thank you!
Kallil Belmonte
35,561 PointsHi Nuno, always when I will implement a more complex plugin, I first begin with an example of the plugin itself, and then I go modifying it to my project. To facilitate this process, I reorganized the structure files/folders for you. What is your email address? (So I can send it to you)
Nuno Nunes
8,849 PointsPlease send it to elfo106@hotmail.com
You are awesome!
Nuno Nunes
8,849 PointsHi,
I'm looking at your files. It's more simple this way :)
As far as I understand, I need obviously the index.html and modify to have the filter option that I want, then I need to change the movies.js to have the data that I want instead of these movies, I need filter.js as it is, and then modify the javascript.js to the class names that I use in index.html
For now I've one question before starting to do some changes:
In the index.html id="movie-template" there are some tags that are strange to me like
<h4><%= _fid %>. <%= name %></h4>
I guess <%= %> is to include a variable content and _fid and name are variable names.
Where are the declarations of _fid and name? Is it in movies.js? I know that _fid correspondes to the movie number (like a db index) but I dont see its declaration anywhere...
Kallil Belmonte
35,561 PointsHi Nuno, For what I see all these "variables" are at the movies.js file, for example:
var movies = [
{
"name": "The Shawshank Redemption",
"outline": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.",
"rating": 9.3,
"director": "Frank Darabont",
"year": 1994,
"stars": [
"Tim Robbins",
"Morgan Freeman",
"Bob Gunton"
],
"runtime": 142,
"genre": [
"Crime",
"Drama"
],
"certificate": "R",
"date": "1974-04-30T10:29:29+05:30",
"actor": "Tim Robbins",
"id": 1
}, ...
<%= rating %> = "rating": 9.3
<%= _fid %> = "id": 1
<%= name %> = "name": "The Shawshank Redemption"
<%= outline %> = "outline": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency."
<%= runtime %> = "runtime": 142
...
Nuno Nunes
8,849 PointsHow _fid is id ? Where the _f came from? :)
Kallil Belmonte
35,561 PointsThe "_fid" appears 8 times at the filter.js file, maybe it is where its definition comes from.
Nuno Nunes
8,849 PointsHi,
I want to have um li with a p and a for each item array in the movies.js but when I use
<li><div class="className"> <p><%= items %></p> <a href="" title=""><img src="img/play.png" alt=""/></a> </div></li>
I get obviously one bullet point with all the items written in the same line and one image in the end. Do you know how I can split all the itens in different lines?
Kallil Belmonte
35,561 PointsI would suggest you take a look at your css (how it is stylized) with your browser inspector tool, and then change it as you want.
Nuno Nunes
8,849 PointsIf you say so...but to be honest I don't think it's a css thing.
I think the tag <%= items %> is grabbing all the array items of my object and putting it all together in a unique "string"
If it was a css thing I would get one image per array item (like I want) but not splitted in different lines.
Am I wrong?
Nuno Nunes
8,849 PointsIf I use <%= items[0] %> I get only the first array item.
Kallil Belmonte
35,561 PointsSend me your project folder via email please.
PS: I never used this plugin before, so I will try to figure it out.
Nuno Nunes
8,849 PointsHi,
Did you had any success? The most I could achieve so far was to have a break line by editing the movis.js file :(
Kallil Belmonte
35,561 PointsI didn't receive your email.
Nuno Nunes
8,849 PointsSent again
Nuno Nunes
8,849 PointsI got it already. Thank you for your support!