HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>ShapeDiver Viewer v2</title>
<!-- ShapeDiver Viewer -->
<script defer src="https://viewer.shapediver.com/v2/2.15.0/sdv.concat.min.js"></script>
<link rel='stylesheet' type='text/css' href='https://viewer.shapediver.com/v2/2.15.0/sdv.css'>
<!-- ShapeDiver Viewer Controls and Export Modal Dialog Dependencies -->
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.5/css/uikit.min.css"
integrity="sha256-sO/kKFCHPL4rhYHDyHC2dwGlaIBttifOfQ0ZaGLAheo=" crossorigin="anonymous" />
<!-- UIkit JS -->
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.5/js/uikit.min.js"
integrity="sha256-jN++RwBoYassp9qTuZDfQuptszFdL1Pm4dKZWS5KjjY=" crossorigin="anonymous"></script>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.5/js/uikit-icons.min.js"
integrity="sha256-6pktS+jePPdXx9oCn8r4hS5jR1eq0Ry7vbifYtG0LDU=" crossorigin="anonymous"></script>
</head>
<body>
<!-- ShapeDiver Viewer Main Container -->
<div id='sdv-container' class='shapediver-container-flex shapediver-container-fullsize'
sdv-fullscreen="true">
<!-- ShapeDiver Viewer Settings Controls Container -->
<div id='sdv-container-settings' class='shapediver-settings-flex' style='display: none;'></div>
<!-- ShapeDiver Viewer Viewport Container -->
<div class='shapediver-viewport-flex'>
<div id='sdv-container-viewport' class='shapediver-container-fullsize' style='opacity: 0;'
logginglevel=0 messagelogginglevel=2>
</div>
<!-- The loading icon will be created here -->
</div>
<!-- ShapeDiver Viewer Parameter Controls Container -->
<div id='sdv-container-controls' class='shapediver-controls-flex' style='display: none;'></div>
</div>
</body>
</html>
/*
* This example demonstrates how to add custom controls to the parameter widget of the ShapeDiver Viewer.
*/
/*
* ShapeDiver Viewer Initialisation
*/
var initSdvApp = function(/*event*/) {
// Settings can be defined here, or as attributes of the viewport container. Settings defined here take precedence.
let settings = {
ticket: "2c4fee2a0d9d180ad450b3ec972b088f5ec73f397bff89083623200b2f63bca0d6012f5ded54dc489e3b9ba9923f0caaef289e5c617184246a6788011ca424fafb2a9b13d8f4f767494e4de4ab4a4388376fb1694fd36e8f8198d344df79e1f5df70812492801d88d2c0102989e6f506892546afdc9a-80de84ce75080789b5bf54d4abfc5f07",
modelViewUrl: "eu-central-1",
showControlsInitial: true,
showSettingsInitial: false,
};
// See https://viewer.shapediver.com/v2/2.14.0/doc/SDVApp.ParametricViewer.html for all settings available via the constructor.
window.api = new SDVApp.ParametricViewer(settings);
// There are various controls types. Available types are as follows, which can be set by enum ParameterType ( api.apps.controls.parameterTypes ) or simple string.
// ParameterType.BUTTON | 'button',
// ParameterType.CHECKBOX | 'checkbox',
// ParameterType.CHECKLIST | 'checklist',
// ParameterType.COLOR | 'color',
// ParameterType.DROPDOWN | 'dropdown',
// ParameterType.FILE | 'file',
// ParameterType.GROUP | 'group',
// ParameterType.MODAL | 'modal',
// ParameterType.SLIDER | 'slider'
// ParameterType.STATICHTML | 'statichtml',
// ParameterType.STRING | 'string',
// ParameterType.VECTOR3 | 'vector3',
// All parameters have order property of type number, which sorts parameters in ascending order.
// In case of 'button' parameter type and update need to be defined. If not defined error will be thrown.
// Buttons are affected by type,update,name and order properties. Other properties are ignored.
// Update call back function has boolean as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.BUTTON,
update: function(booleanVal) { console.log(booleanVal); },
name: 'Button test',
order: 1
});
// In case of 'checkbox' parameter type and update need to be defined.
// Checkbox types are affected by type,update,name and order properties. Other properties are ignored.
// Update call back function has boolean as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.CHECKBOX,
update: function(booleanVal) { console.log(booleanVal); },
name: 'Checkbox test',
order: 2
});
// In case of 'checklist' parameter type, choices and update need to be defined.
// Choices parameter needs to be of type array, otherwise error is thrown.
// Value parameter is optional and is defined as array of preselected values.
// Checklist types are affected by type,update,name,choices, value and order properties. Other properties are ignored.
// Update call back function has selected values array as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.CHECKLIST,
update: function(selectedValuesArray) { console.log(selectedValuesArray); },
name: 'Checkbox test',
choices: ['Joe', 'Jane', 'Mark'],
value: ['Jane', 'Mark'],
order: 3
});
// In case of 'color' parameter type and update need to be defined.
// Color types are affected by type,update,name, value and order properties. Other properties are ignored.
// Update call back function has color in 'rgb' format as parameter. For example for red 'rgb(255,0,0)'
// Color can be passed as hex format '#cc00cc', rgb format 'rgb(255,0,0)', rgba format 'rgba(255,0,0,1)', css color name format 'blue'
// You can use window.api.utils.toTinyColor to parse and convert color values in various formats
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.COLOR,
update: function(rgbColorVal) { console.log(rgbColorVal); },
value: '#cc00cc',
name: 'Color test',
order: 4
});
// In case of 'dropdown' parameter type, choices and update need to be defined.
// Choices parameter needs to be of type array, otherwise error is thrown.
// Value parameter is optional and is defined according to some of corresponding values in choices array.
// Checklist types are affected by type,update,name,choices, value and order properties. Other properties are ignored.
// Update call back function has selected value as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.DROPDOWN,
update: function(selecetedVal) { console.log(selecetedVal); },
choices: ['Joe', 'Jane', 'Mark'],
value: 'Jane',
name: 'Dropdown test',
order: 5
});
// In case of 'file' parameter, type and update need to be defined.
// File types are affected by type,update,name, accept and order properties. Other properties are ignored.
// Accept properties can be checked here https://www.w3schools.com/tags/att_input_accept.asp. It can be added as a single string or array of extensions.
// Update call back function has file list as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.FILE,
update: function(fileList) { console.log(fileList); },
name: 'File test',
accept: [".jpg", ".png"],
order: 6
});
// In case of 'group' parameter, type and parameters need to be defined.
// Group types are affected by type,name and order properties. Other properties are ignored.
// parameters property is of type ParameterDefinition which corresponds to other parameters. For example parameters: [ { type: 'button' ...}, { type: 'checklist' ... }]
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.GROUP,
name: 'Group test',
parameters: [
{
type: api.apps.controls.parameterTypes.BUTTON,
update: function(booleanVal) { console.log(booleanVal); },
name: 'Group Button test',
order: 3
},
{
type: api.apps.controls.parameterTypes.CHECKBOX,
update: function(booleanVal) { console.log(booleanVal); },
name: 'Group checkbox test',
order: 1
},
{
type: api.apps.controls.parameterTypes.COLOR,
update: function(rgbColorVal) { console.log(rgbColorVal); },
value: 'blue',
name: 'Group Color test',
order: 4
}
],
order: 7
});
// In case of 'modal' parameters type and modalContent need to be defined.
// Internally UIKit is being used for modal, please refer to https://getuikit.com/docs/modal to see how to use one.
// Modal is created with shapediver_modal_${id} id such as shapediver_modal_f1b69b85-7cf5-4aaa-9f6c-b912d1e01082
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.MODAL,
order: 8,
name: 'Modal test',
modalContent: '<h2 class="uk-modal-title">Headline</h2>'
+ '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'
+ '<p class="uk-text-right">'
+ ' <button class="uk-button uk-button-default uk-modal-close" type="button">Cancel</button>'
+ ' <button id="jq-test-modal-submit" class="uk-button uk-button-primary" type="button">Save</button>'
+ '</p>'
}).then(function(id){
document.getElementById("jq-test-modal-submit").onclick = function(){
UIkit.modal('#shapediver_modal_' + id).hide();
}
});
// In case of 'slider' parameter type and update need to be defined. If not defined error will be thrown.
// Sliders are affected by type,update,name,value,min,max,step and order properties. Other properties are ignored.
// Optional value property is of type number
// Min, max and step correspond to min, max and step properties of html input of types 'number' and 'range'
// Update call back function has number as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.SLIDER,
update: function(val) { console.log(val); },
value: 50,
name: 'Slider test',
min: -100,
max: 100,
step: 0.5,
order: 9
});
// In case of 'statichtml' parameter type and content need to be defined. If not defined error will be thrown.
// Static html is affected by type, content and order properties. Other properties are ignored.
// Content is any html valid string
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.STATICHTML,
content: '<h1><span class="uk-label">Static HTML test</span></h1>',
order: 10
});
// In case of 'string' parameter type and update need to be defined. If not defined error will be thrown.
// String is affected by type, name, value, update and order properties. Other properties are ignored.
// Name can be any string
// Update callback has a string as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.STRING,
name: 'Test string',
value: 'Joe',
update: function(val) { console.log(val); },
order: 11
});
// In case of 'vector3' parameter type and update need to be defined. If not defined error will be thrown.
// Vector3 is affected by type, name, value, step, min, max, update and order properties. Other properties are ignored.
// Name can be any string
// Min, max and step correspond to min, max and step properties of html input of type 'number'
// Values needs to be an object with x,y,z properties. Such as { x: -5, y: 10, z: -77}
// Update callback has an objects with x,y,z properties as parameter as parameter.
window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.VECTOR3,
name: 'Test vector',
value: { x: -5, y: 17, z: -25 },
update: function(val) { console.log(val); },
step: 0.5,
min: -100,
max: 100,
order: 12
});
// createParameter returns a promise resolving to an id, which can be used to call removeParameter
let id = window.api.apps.controls.createParameter({
type: api.apps.controls.parameterTypes.COLOR,
update: function(rgbColorVal) { console.log(rgbColorVal); },
value: 'blue',
name: 'Another Color test',
order: -10
})
.then(id => {
console.log('Added parameter with id ' + id);
console.log('Successfully removed parameter?', window.api.apps.controls.removeParameter(id));
});
};
// there is a slight chance that loading has been completed already
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initSdvApp, false);
} else {
initSdvApp();
}
Also see: Tab Triggers