Pinterest splash page in twitter bootstrap -
checkout pinterest's splash page - **(make sure logged out of account or wont see splash page.) image of macbook @ bottom, it's responsive , shrinks , expands depending on size of broweser window.
silly question... how it? , how can done using twitter bootstrap?
if @ <script>
blocks on page, can see how it's done. it's resize listener. here's simplified version:
var htaboveimage = $content.height(), naturalimageht = 450, padding = 150, minimageht = 100; var changefunc = function() { var windowht = $window.height(); var imageht = math.min( math.max(windowht - htaboveimage - padding, minimageht) naturalimageht, ); $image.height(imageht); }; changefunc(); $(window).on("resize", changefunc);
there's no need update width too, because <img>
s automatically resize proportionately when size 1 dimension in css. full code on pinterest updates padding on content above image keep vertically centered.
by way: chrome's developer tools friend when comes questions this! making careful use of these tools, takes minute see what's going on:
- right-click image > inspect element
- resize window , notice there's explicit height in px being set on tag, updating continuously. must done js. who's setting it?
- right-click tag > break on... > attributes modifications
- resize window again , hit breakpoint
- top of call stack buried in minified jquery code – generic code setting css property. what's highest non-jquery piece of code on stack?
- there's code!
Comments
Post a Comment