By the end of today, you will be able to:
We learned about galleries and drop-downs.
src
attribute of the
large img
. That causes the large image to be
displayed there.
this
.
We're going to build an image gallery using jsfiddle. (I'll demo what we will build.)
In the reading, we used an attribute
named data-bigsrc
. That attribute is defined by:
The HTML5 standard
The DOM
The programmer
All of the above
If you make the thumbnails like this:
<img src="big-version.jpg" alt="caption">
With CSS like this:
#gallery img { width: 25% }
Wouldn't that avoid all the hassle with the data-bigsrc
attribute?
Yes, but the gallery images would be the wrong size
Yes, but the gallery images would be slow to load
Yes, but the gallery images would have the wrong ALT
Yes, this is a perfectly good solution
A big picture, say from a digital camera, might be bigger than your screen. Let's suppose it's at least 1000px by 1000px and 250 KB in size. A thumbnail that is 200px by 200px is 1/25th the screen size and probably 1/25th the file size, too, so under 10KB in file size. It will therefore load from the server 25 times faster than the big version. So, thumbnails are worth the effort of creating them.
In the code in the reading, we used the special
variable this
. It means:
The element we modify
The element we get the data from
The element in the DOM that the event happened to
None of the above
The first step is building our image gallery. We'll use images from
this directory. Take a look at
the filenames there and view some of the pictures. Note that the URLs
will all start with http://cs.wellesley.edu/~cs110/reading/potterpics/
Let's start by creating all the HTML we will need. Starting with this image gallery v1 using jsfiddle.
Your solution might look like this:
Some notes on the solution:
data-bigsrc
attribute that you will
need?
figure
with a figcaption
for the big version?
With a partner, draft some code for the event handler function. You can go back to your image gallery v2.
Here are the conceptual steps:
bigsrc
attribute
off this
. Hint: use the
jQuery .attr()
method.
src
attribute for the enlargement
image. Use the .attr()
method again.
When you're ready to test, do this:
jQuery 1.11.0
.
Your solution might look like this:
function galleryClick() { var bigsrc = $(this).attr("data-bigsrc"); $("#big img").attr("src", bigsrc); } // Attach to every gallery image $("#gallery img").click(galleryClick);
This is a good start, but it lacks captions. Add that behavior. Here's a starting point: image gallery v3.
Your solution might look like this:
firstclick or a
secondclick.
display
property. If
it's display:none
, the menu is hidden.
Our drop-downs will use a click to open/close the menu, unlike
the rollover
menus that have been common for many years. Our
reasoning is that menus that use clicking will be more mobile-friendly.
Today, we'll keep things very specific. You'll get to more general approaches in lab.
In the drop-down menu below, how did we get the page to not jump around when we show/hide the menu?
The menu is display:relative
and its parent is display:absolute
The menu is display:absolute
and its parent is display:relative
The menu is display:fixed
The menu is display:static
Click on the "Favorite Things" text
Try the following using the menu above.
$("#menu1").css("display");
Draft some code for this drop-down. You'll need
display
property and act accordingly, namely:
.show()
, and
.hide()
.
Your code might look like this:
Copy it to this jsfiddle and get the code to work.
Your result might look like this:
We hope that after these activities you have a good understanding of:
Will be posted later, visit again after .
Quiz answers:
1. C 2. B 3. C 4. B