What happened to the old image rollover script?
It was not restored, because the editors cannot trace a CodeLifter rollover page in the surviving link records, and the effect no longer needs a script. Two images and a CSS :hover rule do the swap. Add :focus-visible so keyboard users see the same change, and keep anything important out of the hover state.
Cite
CodeLifter Forum, "What happened to the old image rollover script?", https://codelifter.com/forum/posts/what-happened-to-the-old-image-rollover-script/, accessed 2026-11-12.- CodeLifter editorsStaffStaff, CodeLifter ·
What the records show
The Script Shelf lists every old script the editors can tie to a name and an address: fifteen of them, taken from links to the original site that still exist and from the original site's archived pages, checked on 2026-10-15. An image rollover is not among them. That list is not the full original catalogue, so a rollover page may well have existed. If you have a working link to one on the old site, post it in this thread so the shelf can be checked against it.
What the shelf does show is where the old scripts went. Six became reviewed prompts, five were replaced by something built into the browser, and four were retired. A rollover would fall in the second group.
What a rollover script did
The common pattern of that era was a pair of images and two event handlers: on
mouseover, change thesrcof the image to the highlighted version; onmouseout, change it back. Scripts usually preloaded the second image so the swap did not flash. It worked with a mouse and nothing else: no keyboard focus, no touch, and nothing for a screen reader beyond the first image's alt text.Can you keep an old rollover that still works?
Probably, in the narrow sense:
mouseoverandmouseoutstill fire for a mouse, and swapping an imagesrcis ordinary DOM code. The problems are the ones it always had. Keyboard users never see the highlighted state, touch users may get it stuck, and inlineonmouseover="..."attributes are hard to audit next to the rest of your markup. If the rollover is on a link people need to find, replace it with the CSS version below. If it is pure decoration on a page nobody maintains, it can wait until you next edit the file.The CSS version
Put both images inside the link and let CSS decide which one shows:
<a class="swap" href="/catalogue/"> <img src="catalogue.png" alt="Catalogue" width="200" height="120"> <img class="swap-on" src="catalogue-on.png" alt="" width="200" height="120"> </a>.swap { position: relative; display: inline-block; } .swap-on { position: absolute; inset: 0; opacity: 0; } @media (hover: hover) { .swap:hover .swap-on { opacity: 1; } } .swap:focus-visible .swap-on { opacity: 1; } @media (prefers-reduced-motion: no-preference) { .swap-on { transition: opacity 150ms; } }Why each part is there:
- The second image has
alt="". MDN's img reference says an empty alt marks an image as not a key part of the content, so non-visual browsers may skip it. The link's name comes from the first image only. :hoversits inside@media (hover: hover). MDN's :hover page warns that on touchscreens the pseudo-class "might never match, match only for a moment after touching an element, or continue to match" until another element is touched. The hover media feature tests whether the primary input can hover conveniently, so phones skip the effect instead of getting stuck in it.:focus-visiblegives the same change when someone tabs to the link. MDN describes it as matching when the element has focus and the browser decides focus should be made evident.- The fade runs only when the visitor has not asked the system to reduce motion, using
prefers-reduced-motion.
Both images download with the page, so there is nothing to preload.
Old and new side by side
Script rollover CSS rollover Trigger mouseoverandmouseouthandlers:hoverand:focus-visibleKeyboard No change on focus Same change on focus Touch Often stuck in one state Effect skipped where hover is not convenient Works with JavaScript off No Yes Code to maintain Handlers per image, preload list One rule set for every .swaplinkIf you ask an assistant for one
Ask for the behaviour, not "a rollover script", or you may get the 1999 pattern back with
onmouseoverattributes. Lines worth putting in the prompt:- "Use CSS only:
:hoverinside@media (hover: hover), plus:focus-visible. No JavaScript." - "The second image is decorative:
alt=""." - "Do not put any text or link that only appears on hover."
- "Wrap any transition in
prefers-reduced-motion: no-preference."
How to write a coding prompt explains why naming the failure modes works better than naming the effect. The keyboard prompting thread covers the same idea for scripts that do need JavaScript, and if you still have an old rollover pasted into a page, the thread on whether old cut-and-paste scripts still work explains what to check before you leave it there.
- The second image has
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.
2 answers
- CodeLifter editorsStaffStaff, CodeLifter ·
Does :focus-visible work in all current browsers? Yes. MDN's :focus-visible page marks it Baseline widely available, working across browsers since March 2022. The pseudo-class matches when an element has focus and the browser decides, by its own heuristics, that the focus should be shown. MDN's example: when a button is clicked with a pointing device, focus is generally not shown, but when someone tabs to it, it is. So a keyboard user tabbing to the rollover link gets the highlighted image, while a mouse click usually does not leave it showing. That is why the CSS in the opening post uses
:focus-visiblerather than:focus. If you must support a browser older than that, MDN suggests repeating the focus styling under:focusinside an@supportstest, and notes that an old browser with no custom:focusrule still shows its native outline, which may be enough. The page also gives a contrast requirement that is easy to miss on an image swap. WCAG 2.1 success criterion 1.4.11, Non-text Contrast, asks for a visible focus indicator of at least 3 to 1. A highlighted image that differs only slightly from the plain one may not meet that, so keep the browser's own outline on the link as well, and do not addoutline: noneto.swap. - CodeLifter editorsStaffStaff, CodeLifter ·
Does a hover effect work on a touchscreen laptop? It depends on which input the browser treats as primary, and CSS can ask about both. The opening post wraps the rollover in
@media (hover: hover), which tests the primary input. MDN's any-hover page describes the companion feature:any-hovertests whether any available input mechanism can hover. It takes two values,hover, when one or more inputs can hover conveniently, andnone, when none can or there is no pointing device. It has worked across browsers since December 2018. On a laptop with a touchscreen and a trackpad,(any-hover: hover)can match even when the primary input is touch, so a rule written withany-hovershows the effect to the trackpad user, whilehovermay hide it from everyone on that device. For a decorative image swap,hoveris the safer choice: nobody loses anything if the effect is skipped. For a control that only reveals itself on hover, neither query is enough, and the opening post's rule applies: do not put anything people need in the hover state. Pair either query with:focus-visibleso keyboard users get the same change.