Follow these steps to create a one-page web gallery:
<h3>One-Page Web Design Gallery</h3> <ul> <li><a href="http://packtpub.com" rel="gallery">Packt Publishing</a></li> <li><a href="http://nataliemac.com" rel="gallery">NatalieMac</a></li> <li><a href="http://google.com" rel="gallery">Google</a></li> </ul>
Note that I've added a rel
attribute equal to gallery
to each link.
scripts.js
file and add our document ready statement:$(document).ready(function(){ });
rel
attribute equal to gallery
and call the colorbox()
method:$(document).ready(function(){
$('a[rel="gallery"]').colorbox();
});
iframe
key to true
since we're loading in content from other domains. I'm also going to set the width
and height
of the ColorBox to 90%
, so that it takes up nearly the entire browser window. I'm also going to adjust the pagination indicator text to read Web Site
instead of Image:
$('a[rel="gallery"]').colorbox({
iframe: true,
width: '90%',
height: '90%',
current: 'Web Site {current} of {total}'
});
Now, if you refresh the page in the browser, you can see that clicking one of the links opens a Colorbox and loads that website into the Colorbox. A site visitor can interact with the loaded website just as they would if they had loaded it into a separate browser window, browsing through pages, and so on. When finished with one site, they can click the next arrow to visit the next website in the list and then hit the Esc key on the keyboard or click the close button or anywhere outside the Colorbox to close the Colorbox when they're finished.
Note that it is possible for website owners to block your ability to load their sites into an iframe
. If you have set up a local server using MAMP or WAMP, then you might notice that the Google example won't load into your page. It will, however, load if you upload your code to an external server. Be sure to test all the sites you want to use in your web gallery to ensure that they work as expected.
What just happened?
We used much of what we learned creating a Colorbox video player to display external websites inside a Colorbox. This allows our site visitor to browse a collection of websites without ever leaving our page. We once again told Colorbox to load our content into an iframe
to work around cross-domain Ajax restrictions. We customized the pagination indicator text, and set a width and height for our Colorbox.
3.141.24.134