I see this mistake way more often than I should. Someone adds an event listener with an anonymous function callback to an element (like a button) then puts it in a a function that may get called multiple times. While this very common setup may seem harmless, it can create some serious issues.
The problem is this setup will add multiple listeners to the element, a new one each time the function is called, meaning three calls will add three listeners, then when the event is triggered the callback will be run three times. This JSFiddle demo clearly shows the scenario in action.
Continue reading “JS – Avoid duplicating addEventListener()”
According to the documentation,
defer a script?), so I wrote my own function using the basic idea of that snippet, which is the topic of this article. 🙂
You know what link anchors are, correct? They are used to jump between different sections of the same page. Quite often when a link anchor is clicked, the page smoothly scrolls to the desired location. However, smooth scrolling is not the native behavior. No, the native behavior for link anchors is to instantly jump between sections, which can be jarring and unpleasant. That is why many developers smooth it out using jQuery scripts like this one.
I too enjoy it when anchor links smoothly scroll, but for the last few months I have on a “jQuery fast” and it has severely limited my smooth scrolling options. Smooth scrolling is impossible to recreate with CSS transitions, I have had limited success using
requestAnimationFrame, and fun scroll-to-top buttons like Elevator.js are not appropriate. I have really been in the dark on filling the hole left by removing jQuery.
Continue reading “JS – Smooth scrolling without jQuery”
This is why we cannot always have nice things in web development.
Like anything in web development, developers have a choice to make: do they use technology in a responsible, law-abiding manner or not? Do they write code and systems that are helpful and beneficial to the visitor or not? As much as I would like to see everyone using their talents for good, I know that does not happen. Who do you think black-hat hackers are and what they do?
Continue reading “Uncovering a super-persistent tracking cookie”
I was looking at the PHP 7.0.0 Beta 1 change log the other month wondering how much the language would *ahem* improve in this new, major release. As I was reading, I was surprised to come across this change:
Continue reading “JS – Multiple parameters with the same name?”
The more I work with PHP, the crazier it becomes.
Continue reading “PHP – Accessing data sent over POSTed AJAX”
Calculating the difference between two dates is much easier in PHP thanks to the
date() (I recommend using “j”, “n”, and “Y”). You might also require running
date_default_timezone_set("UTC"); before that depending on your server configuration.
On to the code! 😀
Continue reading “PHP – Calculate your age”