Here’s a not so quick tutorial on how to create a toggle switch for pricing:
Here’s the JSON for toggle:
{"tags":[{"tags":[],"symbol":null,"order":100,"loop":1,"name":"span","label":"Span","attributes":{},"classes":{},"conditions":{},"properties":{},"text":{"1":"Monthly"},"css":{},"Target":null},{"tags":[],"symbol":null,"order":300,"loop":1,"name":"span","label":"Span","attributes":{},"classes":{},"conditions":{},"properties":{},"text":{"1":"Yearly"},"css":{},"Target":null,"target":{"0":{},"length":1}},{"tags":[{"tags":[],"symbol":null,"order":100,"loop":1,"name":"div","label":"Circle","attributes":{},"classes":{},"conditions":{},"properties":{},"text":{},"css":{"1920":{"self":{"height":"24px","width":"24px","background":"rgba(0,0,0,1.00)","border-radius":"100%","position":"absolute","top":"3px","left":"3px","right":"auto","bottom":"auto","transition":"all 200ms 0ms linear"}}},"Target":null}],"symbol":null,"order":200,"loop":1,"name":"div","label":"Toggle","attributes":{"1":{"class":"toggle"}},"classes":{"1":[]},"conditions":{},"properties":{},"text":{},"css":{"1920":{"self":{"width":"60px","height":"30px","background":"rgba(255,255,213,1.00)","border-radius":"100px","position":"relative","transition":"all 200ms 0ms linear"},".dh-active":{"background":"rgba(253,253,87,1.00)"},".dh-active div":{"left":"50%"}}},"Target":null}],"symbol":null,"order":100,"loop":1,"name":"div","label":"Toggle Wrapper","attributes":{},"classes":{},"conditions":{},"properties":{},"text":{},"css":{"1920":{"self":{"display":"flex","align-items":"center","column-gap":"10px","justify-content":"center"}}},"Target":null}
Here’s the JS code I used:
$(document).on('click','.toggle',function(){
$(this).toggleClass("dh-active");
if ( $(this).hasClass("dh-active") ) {
$(".price-y").show();
$(".price-m").hide();
$(".price-text").text("/per year");
} else {
$(".price-y").hide();
$(".price-m").show();
$(".price-text").text("/per month");
}
});