Media queries present an effective way to programmatically change habits relying on viewing state. We will goal kinds to machine, pixel ratio, display screen dimension, and even print. That stated, it is also good to have JavaScript occasions that additionally permit us to alter habits. Do you know you are supplied occasions each earlier than and after printing?
I’ve at all times used @media print
in stylesheets to manage print show, however JavaScript gives beforeprint
and afterprint
occasions:
operate toggleImages(cover = false) { doc.querySelectorAll('img').forEach(img => { img.fashion.show = cover ? 'none' : ''; }); } // Disguise pictures to save lots of toner/ink throughout printing window.addEventListener('beforeprint', () => toggleImages(true)) window.addEventListener('afterprint', () => toggleImages());
It might sound bizarre however contemplating print is essential, particularly when your web site is documentation-centric. In my early days of internet, I had a shopper who solely “considered” their web site from print-offs. Styling with @media print
is normally the perfect choices however these JavaScript occasions might assist!
fetch API
One of many worst stored secrets and techniques about AJAX on the net is that the underlying API for it,
XMLHttpRequest
, wasn’t actually made for what we have been utilizing it for. We have executed nicely to create elegant APIs round XHR however we all know we are able to do higher. Our effort to…
PHP IMDB Scraper
It has been fairly some time since I’ve written a PHP grabber and the itch lastly acquired to me. This time the sufferer is the Worldwide Film Database, in any other case often called IMDB. IMDB has information on each film ever made (or so it appears). Their…
Spotlight Desk Rows, Columns, and Cells Utilizing MooTools 1.2.3
Row highlighting and particular person cell highlighting in tables is fairly easy in each browser that helps :hover on all parts (mainly every part besides IE6). Column highlighting is a little more troublesome. Fortunately MooTools 1.2.3 makes the method simple. The XHTML A traditional desk. The cells…
Source_link