A set of tools to help detect when your pen is being shown in a thumbnail view and simulate mouse movement.
As an example, the content of this pen looks different in its preview thumbnail and the cursor circle moves automatically. See here.
Please keep in the spirit of CodePen. Don't use this tool to show something completely different, click baity or disingenuous in the thumbnail preview.
Simply add this CodePen pen to your CodePen pen. Pen.
In other words - When you're in your pen's editor, click the setting button top right, select the javascript tab and paste in this link as an external script...
https://codepen.io/ste-vg/pen/xeZOMK
There is a CodePen object available in JS so you can check if the pen is in a thumbnail/preview window.
CodePen.isThumbnail
CodePen.view
This can equal one of the following: 'THUMBNAIL', 'EDITOR', 'DEBUG', 'DETAILS' or 'FULL_PAGE_OR_EDITOR'
When a pen first loads in the editor view it's not possible to tell if it's in a full screen view or editor view. If the pen is edited and dynamically reloaded it can then determine it's in an editor view.
This allows you to listen to mouse and touch events. The advantage of using this is it automatically simulates mouse movement when in thumbnail mode.
let input = CodePen.input()
input.onDown(point => console.log('mouse down', point))
input.onMove(point => console.log('mouse move', point))
input.onUp(point => console.log('mouse up', point))
You can see the circle following your mouse here, but in the thumbnail it will move on its own. Useful if your pen only shows something in reaction to mouse movement. See some examples here
The output from the CodePen.view gets automatically added as a class to the body.
The CodePen thumbnail tool also sets some custom properties that allows you to hide or show content.
var(--codepen-thumbnail)
Will equal 1 if inside a thumbnail or 0 if not.
var(--codepen-thumbnail-display-block)
Will equal 'block' if inside a thumbnail or 'none' if not.
display: var(--codepen-thumbnail-display-none, block)
Will equal 'none' if inside a thumbnail and is unset if not. I recommend you use a default value with this one.