Posts tagged code
– page 4

Using Bookmarklets for Basic Chrome for iOS Debugging

So I was trying to figure out a design bug that could only be recreated in the Chrome browser on an iPhone and it was kind of a hassle. Safari on iOS and the Chrome DevTools emulator looked fine so they were no help. Xcode’s simulator and remote debugging only work with Safari so they were out too. I know there are other resources you can either pay for or take the time to install that might get the job done but I really only needed to test a couple lines of CSS.

I remembered from years back that Firebug Lite could run on any browser or mobile device but it’s actually a little heavy and hard to use on a small screen. But — looking it up — I had the epiphany that if you know JavaScript there’s no reason you can’t just make your own bookmarklet for debugging. This might be totally obvious but it took a while to occur to me so there you go.

If you want to do a really quick styling update, all you need is something like this (note: this is not the issue I was trying to fix):

javascript:(function () {
    var el = document.querySelector('body');
    el.style.color = '#fff';
    el.style.backgroundColor = '#000';
})();

Or, if you want to insert an external file:

javascript:(function () {
    var src = 'path/to/styles.css';
    var link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href = src;
    document.head.appendChild(link);
})();

Then you just open Chrome and create a dummy bookmark, select edit, and replace the URL field with your JavaScript. You can also rename the bookmark to something more accurate if you want.

For more information, TutsPlus has a useful tutorial on creating bookmarklets.

Blind-style Nav Transition

I’ve been playing around with new animations for fullscreen navigation menus and thought I’d share. The Pen below is a sort of window blind/disappearing curtain swipe transition.

See the Pen Nav Animation Experiment by Lauren Ashpole (@laurenashpole) on CodePen.

Diagonal Hover Effects with Skew

Just finished up a quick Pen to try out some diagonal swipe/background hover animations using transform: skew.

I have an example page here and you can check out the code below. All of the background images are courtesy of Unsplash It.

See the Pen Diagonal Hover Effects by Lauren Ashpole (@laurenashpole) on CodePen.

AMP forms with Node.js

UPDATE 11/14/19: At some point in the years since I originally posted this, Google made some improvements to the way AMP handles URLs and I’ve updated my headers to keep up. Most of the information below is still applicable but I’ve updated the Access-Control-Allow-Origin and AMP-Access-Control-Allow-Source-Origin settings to:

res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader('AMP-Access-Control-Allow-Source-Origin', req.query.__amp_source_origin);

So keep that in mind while reading the original post…


I’m in the middle of creating Google AMP pages for my fonts and everything was going pretty well until I tried getting the amp-form component working with Node.js. I followed the AMP by Example code, my page passed validation, but whenever I tried to use the form data all I got was an empty req.body.

Finding a solution took more effort than the usual reading through the first few Stack Overflow results, so I thought it might be useful for anyone else out there struggling.

Continue Reading

Advertisement
Advertisement

Positioning Rotated Text

Using transform: rotate() for a sideways text effect is pretty simple CSS but if you’re anything like me, you forget the details for positioning that text and have to play around with translates and transform-origins in the Inspector every time.

So I made myself a cheatsheet for positioning rotated text and thought I’d share it. You can align text to the top, center, or bottom of its parent container and change the direction of the text up or down.

Check it out here.

Animated Drawer with Fixed, Variable Height Header

This is a fairly common request in my office: slide in animated drawers with fixed headers and scrollable bodies. Also, the content in the headers is constantly changing so both the body and header heights need to adapt.

Before flexbox, this was kind of a nightmare. Absolute positioning doesn’t play particularly nice with transforms. Multiple classes to set multiple heights seems like overkill. So does using JavaScript just to get this layout.

But with flexbox, it can be done in basically four lines (eight with prefixes). Use a flexbox column display for the drawer itself:

.drawer {
    display: -webkit-box;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    flex-direction: column;
}

And set the drawer body to grow and scroll:

.drawer-body {
    -webkit-box-flex: 2;
    flex-grow: 2;
    overflow-y: auto;
}

That’s all it takes. Here’s a Pen that also includes the code for animating on and off the page.

See the Pen Animated Drawer with Fixed, Variable Height Header by Lauren Ashpole (@laurenashpole) on CodePen.

CSS3 Animated Geometric Loaders

A lot of Destiny playing has been going on in my apartment lately and after weeks of seeing it whenever I glanced up at the TV screen, I was inspired to work on a few geometric animations.

You can view the results here.

The code is embedded below or you can get it directly at CodePen.

See the Pen CSS3 Animated Geometric Loaders by Lauren Ashpole (@laurenashpole) on CodePen.

CSS3 Animated Social Sharing Buttons Revisted

An update on a quick post I wrote a while back about some social sharing buttons I was working on. I just cleaned up that pen a bit — created examples for each sharing service, prefixed the CSS, added a new animation option — so a demo page to show them off seemed in order.

The demo page is here and the code is here.

I should also mention that the social icons all come from Font Awesome and the background were much easier thanks to this post.