How can I duplicate Pinterest website's modal effect?
Asked Answered
N

5

32

I would like to create the same effect as on Pinterest when you click on an image: a modal window opens up but the URL of the page also changes. This last part is crucial: the URL in the address bar of the browser has changed, but we still see the original page content in the background (that's why I call it a modal even though it may be much more complicated than that). I am ideally looking for a jQuery solution.

[edit] I should add that of course the Pinterest behaviour does not break the Back button which is, again, crucial.

Needs answered 28/6, 2012 at 20:42 Comment(0)
R
50

This is my assessment of how Pinterest achieves it's unique modal look and how to duplicate it.

First and foremost, URL Link handling is server-side analyzed to see if the link is originating from the Pinterest site itself. That said, the Browsers URL Address Bar and History are dynamically created and not actually performed by the visitor.

To clarify: The address bar is not the actual place your at when a model experience is taking place! To prove this, click on a Pinterest object and when in modal view go to the Address Bar and at the end of that URL location place your mouse cursor there and then click enter. You will then redirect yourself to that location! For further verification that you never left the home page, view Net Tab in Firebug/Firefox or Network Tab in Chrome.

The following method is what Pinterest is doing when visiting the home page. Please view gingerly:

  1. Show Home Page.
  2. Wait for visitor to click on a Pinterest object.
  3. The clicked object has a unique webpage for direct access.
  4. The clicked object is not followed.
  5. The browser bar will populate itself with this clicked objects location, but your not actually there.
  6. The browser history will receive clicked location via JavaScrict or Server-Side processing.
  7. AJAX will load a piece of data (meat of modal via ID) from object's page. Verifiable via HTTPRequest.
  8. The clicked object on the main page has disappeared (This can be verified via Inspect Element).
  9. The AJAX process will place that piece of data in the center of the screen with a white overlay.
  10. Scrolling main page is disabled while AJAX "modal" data receives scroll events via #zoomScroll.
  11. Clicking modal background returns object to webpage and URL Address Bar is "visually" reverted.

To recreate the model effect Pinterest uses I would investigate different lightbox's that support HTML/iframed content. Reviewing the numbered steps above process will show how to achieve the desired look for your website.

A key step would be to set the lightbox to use all of the viewport, modifying the lightbox CSS rules if required to avoid any Close Button skin graphics and borders.

The lightbox can then use a single template file with a div that's populated by AJAX. Said div is horizontally centered in the viewport on a semi-transparent background. The iframe itself is transparent which would allow the underlying home page to show through.

Throw in some scrolling rules similar to Pinterest and you have a decent clone method to use.

As far as duplicating the Pinterest Webpage Layout, see this SO Answer.

To use custom Pinterest Button that is text-link, thumbnail, or combo of both, see this SO Answer.

For Data Scrape Pinterest process with jsFiddle tutorial, see this SO Answer.

Relucent answered 28/6, 2012 at 22:41 Comment(0)
G
10

I don't have enough rep to comment on arttronics answer but I wanted to add this:

The browser bar is manipulated through the newer HTML 5 history. This particular case can be done with:

window.history.pushState({}, "Some Title", "the url")

https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history/#The_pushState().C2.A0method

Gaylegayleen answered 17/7, 2012 at 22:27 Comment(2)
Hi Jspies, I haven't had the time to delve into this question but I will have to get to it soon. But your answer makes a lot of sense and would explain why the mechanism does not work on IE (even IE 9)... maybe IE9 is not up to date on this HTML5 API?Mansuetude
I have it working on an app in development, but have only tested in Chrome, Safari and Firefox. There's an SO thread on IE9 and history they mention a js library History.js, but I have not tried it.Gaylegayleen
S
1

This guy call this pinterest style

but modal window opening looks different

http://codecanyon.net/item/jquery-pinterest-style-gallery-plugin/2463876

If you can add white overlay it looks .

look this too

http://hasin.me/2012/03/10/building-a-nice-image-gallery-like-pinterestfriendsheet-using-facebook-graph-api-and-lightbulb/

this too

http://www.asual.com/jquery/address/

Sumo answered 28/6, 2012 at 21:11 Comment(6)
Again I must stress that the question is not about creating a gallery, or opening a modal dialog, but emulating this behaviour:I click on a link on a page and the browser URL changes (hence the Back button is not broken) but the original page still shows "through" or "behind" the new "modal" window.Mansuetude
i think url changing is not happening by the gallery. on clcik of gallery you have to rewrite the url. dont think that some will come and give you the exact code you want . or try the printerest clone!Sumo
What do you mean by "i think url changing is not happening by the gallery"?. If you are talking about Pinterest, then yes it does.Mansuetude
then what you asking . you want to change the url . its happening on the seo side. what you did till now ? can you show the code you tried ?Sumo
My question is as posted on top of this page. I would like to end this conversation with you now as it seems you are not so much trying to help but rather to tell me my question is not valid. I think my question is valid and before I change my mind about this particular fact I would like a second, and most likely third, opinion.Mansuetude
@Sébastien, in all fairness your starting words are I would like to create the same effect for which this answer seems to address. Sometimes a re-edit to the Question's content is needed when 1 or more persons interpret what you wrote in a manner that you did not intend. I see nothing the matter for what zod wrote, apart from an answer that may help others visiting your Question. Cheers!Relucent
P
1

Here is an example with a bit of code with a JQuery modal dialog.

http://jsfiddle.net/aDCQL/2/

This is really just a proof of concept and could possibly be expanded upon...

Utilizing a hashing library, you can perform certain functions based on a URL and provide direct links to those same functions. This library supports all the browsers we care about.

Actual path routing libraries also exist that also simplify some of these path definitions.

https://github.com/cowboy/jquery-hashchange

Panicle answered 28/6, 2012 at 23:11 Comment(1)
+1 I like your answer since your talking about Deep Linking via HASH. That does create unique URL History and also allows for hidden content on the webpage to be used without relying on AJAX request. At first, I thought that was the process Pinterest uses but your idea is sound for a different implementation.Relucent
C
0

How about prettyPhoto? It adds #prettyPhoto[gallery]/x/ to the URL.

Culbertson answered 28/6, 2012 at 21:37 Comment(1)
Unfortunately this is still not a URL change. # represents a fragment of the same URL. Also, ideally I would like a more simple, less "packaged" solution. But if it works I could at least study the script... This one doesn't though, or did I miss something?Mansuetude

© 2022 - 2024 — McMap. All rights reserved.