ripple effect on button-like widgets
new push button widget
This commit is contained in:
parent
e217a189cd
commit
48b6db0d9a
4 changed files with 92 additions and 7 deletions
File diff suppressed because one or more lines are too long
|
|
@ -96,8 +96,11 @@ parsewidgets = function(widgets,parent) {
|
|||
style = styleW + ';' + styleH
|
||||
|
||||
|
||||
// Sort widgets' properties and turn string-numbers to numbers
|
||||
for (k in widgetOptions[widgetData.type]) {
|
||||
var tmp = widgetData[k]
|
||||
if (parseFloat(tmp)==tmp) tmp=parseFloat(tmp)
|
||||
if (parseInt(tmp)==tmp) tmp=parseInt(tmp)
|
||||
delete widgetData[k]
|
||||
widgetData[k] = tmp
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,16 @@ widgetOptions = {
|
|||
path:'auto',
|
||||
target:[]
|
||||
},
|
||||
push: {
|
||||
id:'auto',
|
||||
label:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
off:0,
|
||||
on:1,
|
||||
path:'auto',
|
||||
target:[]
|
||||
},
|
||||
switch: {
|
||||
id:'auto',
|
||||
label:'auto',
|
||||
|
|
@ -169,9 +179,7 @@ createWidget.toggle = function(widgetData) {
|
|||
<div class="toggle">
|
||||
<div class="light"></div>
|
||||
</div>\
|
||||
`),
|
||||
led = widget.find('.light')
|
||||
|
||||
`)
|
||||
|
||||
widget.value = widget.find('span')
|
||||
|
||||
|
|
@ -189,11 +197,9 @@ createWidget.toggle = function(widgetData) {
|
|||
off= widgetData.off
|
||||
if (v==on) {
|
||||
widget.addClass('on')
|
||||
if (widgetData.color) led[0].setAttribute('style','background:'+widgetData.color)
|
||||
if (send) widget.sendValue(v)
|
||||
} else if (v==off) {
|
||||
widget.removeClass('on')
|
||||
if (widgetData.color) led[0].setAttribute('style','')
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
|
||||
|
|
@ -201,6 +207,60 @@ createWidget.toggle = function(widgetData) {
|
|||
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
if (v===false) return
|
||||
sendOsc({
|
||||
target:widgetData.target,
|
||||
path:widgetData.path,
|
||||
args:v
|
||||
})
|
||||
}
|
||||
widget.setValue()
|
||||
return widget
|
||||
}
|
||||
|
||||
createWidget.push = function(widgetData) {
|
||||
|
||||
var widget = $(`
|
||||
<div class="push toggle">
|
||||
<div class="light"></div>
|
||||
</div>\
|
||||
`)
|
||||
|
||||
widget.value = widget.find('span')
|
||||
|
||||
widget.on('drag',function(){})
|
||||
widget.on('draginit',function(){
|
||||
widget.setValue(widgetData.on,true)
|
||||
widget.on('dragend',function(){
|
||||
widget.setValue(widgetData.off,true)
|
||||
widget.off('dragend')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
widget.getValue = function() {
|
||||
return widget.hasClass('on')?widgetData.on:widgetData.off
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
var on = widgetData.on,
|
||||
off= widgetData.off
|
||||
if (v==on) {
|
||||
widget.addClass('on')
|
||||
widget.removeClass('ripple')
|
||||
setTimeout(function(){
|
||||
widget.addClass('ripple')
|
||||
},1)
|
||||
if (send) widget.sendValue(v)
|
||||
} else if (v==off) {
|
||||
widget.removeClass('on')
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
|
||||
if (send) widget.trigger('sync')
|
||||
|
||||
}
|
||||
widget.sendValue = function(v) {
|
||||
if (v===false) return
|
||||
sendOsc({
|
||||
target:widgetData.target,
|
||||
path:widgetData.path,
|
||||
|
|
|
|||
|
|
@ -762,7 +762,7 @@ a {
|
|||
|
||||
/* BUTTONS */
|
||||
|
||||
.toggle-container {
|
||||
.toggle-container, .push-container {
|
||||
width:100rem;
|
||||
min-height: 65rem;
|
||||
flex-shrink: 0;
|
||||
|
|
@ -810,10 +810,26 @@ a {
|
|||
}
|
||||
&.on .light {
|
||||
background: $color-accent;
|
||||
animation: ripple .25s linear;
|
||||
animation-fill-mode:backwards;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.push {
|
||||
&.on .light {
|
||||
animation:none;
|
||||
}
|
||||
&:active .light {
|
||||
background: $color-accent;
|
||||
}
|
||||
&.ripple .light {
|
||||
animation:ripple 0.25s linear;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.switch-container {
|
||||
// height: 100%;
|
||||
width:100rem;
|
||||
|
|
@ -882,6 +898,7 @@ a {
|
|||
&.on {
|
||||
&:after {
|
||||
background: $color-accent;
|
||||
animation:ripple 0.25s linear;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -889,6 +906,11 @@ a {
|
|||
}
|
||||
|
||||
|
||||
@keyframes ripple {
|
||||
/*scale the element to 250% to safely cover the entire link and fade it out*/
|
||||
0% {box-shadow: 0 0 0 0 rgba($color-accent,.5)}
|
||||
100% {box-shadow: 0 0 0 100rem transparent;}
|
||||
}
|
||||
|
||||
|
||||
/* XY */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue