惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
Martin Fowler
Martin Fowler
爱范儿
爱范儿
IT之家
IT之家
Last Week in AI
Last Week in AI
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
aimingoo的专栏
aimingoo的专栏
G
Google Developers Blog
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
The Cloudflare Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog

CloudCannon Blog

Building with AI: Git-based vs headless vs traditional CMS CloudCannon + Astro: performance meets powerful content management Introducing the Astro Component Starter Introducing Jetstream — built on the Astro Component Starter Why we switched to the system font stack Redesigning CloudCannon’s docs with Diátaxis, Lume, and Pagefind Make content editing more visual: upgraded Editable Regions How Configuration Mode makes building editing interfaces easy Your hosting just got an upgrade (and a price cut) Custom testing domains for professional branding Keep your content consistent with input validation Managing multilingual content in CloudCannon Simplify team publishing with conflict resolution and domain tools Open Beta: Publishing Conflict Resolution Getting started with CloudCannon and Astro: Bookshop, components, and live editing Welcome to the CloudCannon Community! Omnichannel delivery is just marketing spin from API-based CMS companies Getting started with CloudCannon and Astro: Snippets and Collections Managing digital assets in CloudCannon: a guide to smart asset storage Understanding CloudCannon's branching workflows and Projects: a complete guide What is a static website? CloudCannon’s 2024 wrapped Getting started with CloudCannon and Astro: WYSIWYG blogging Jamstack vs. WordPress: reasons to make the change The top five static site generators for 2025 (and when to use them!) Free Jekyll themes for 2025: ten great community options Eleventy (11ty) vs. Hugo How to set up WYSIWYG editing with MkDocs Material The rise of static-first websites: why major brands are making the switch Watching your Core Web Vitals on Jamstack
Using CloudCannon with JavaScript
2014-04-18 · via CloudCannon Blog

A common question that comes up is “How can I use JavaScript with CloudCannon?”. As a heavy JavaScript user, I would ask the same and that’s why we build CloudCannon from the ground up to handle a wide range of sites.

There is one rule to know when using JavaScript with the editable class. The elements with an editable class must not be rendered or tampered with by the JavaScript.

Sliders/Carousels Direct link to this section

CloudCannon allows you to add the editable class to content that is no visible on page load. As long as the content is on the page to start with it should work.

To demo this I am going to use unslider. To add the slider we just need a div with all the slides with their own container:

<div class="banner">
<ul>
<li>This is a slide.</li>
<li>This is another slide.</li>
<li>This is a final slide.</li>
</ul>
</div>

Then all we need to do is include the scripts required and add a single line of JavaScript:

var options = {
speed: 500, CLOUDCANNONANNOTATION1
delay: 3000, CLOUDCANNONANNOTATION2
dots: true CLOUDCANNONANNOTATION3
};

$('.banner').unslider(options);

The speed to animate each slide (in milliseconds).

The delay between slide animations (in milliseconds).

Hurray, if we test this we see that we have editable content within a slider. One problem though, the library is messing with the inline editing. Every time the arrow keys are pressed the next slide is shown rather than changing my caret position. That’s Ok, we just need to disable the arrow keys and the autoplay on the site while inside the editor.

var options = {
speed: 500, CLOUDCANNONANNOTATION1
delay: 3000, CLOUDCANNONANNOTATION2
dots: true CLOUDCANNONANNOTATION3
};

if (window.inEditorMode) {
options.keys = false;
options.delay = false;
}

$('.banner').unslider(options);

The speed to animate each slide (in milliseconds).

The delay between slide animations (in milliseconds).

This means we have a customisable slider which works well in both the live site and in the client editor.

Accordions Direct link to this section

Accordions are another way of showing and hiding related content. They help declutter a screen and are perfect for things like FAQs. There is a good tutorial on how to make a simple jQuery accordion on jacklmoore.com. This will work perfectly just by adding the editable class to any of the content.

That’s all today Direct link to this section

Thanks for reading. If you want me to go over any other kind of JavaScript UI modules or somethings unclear feel free to send me a message. To keep up to date on these posts make sure to follow us on Twitter.