토글 버튼
Last updated
Last updated
이미지를 불러온 뒤 `over` state를 비활성 시킨 이유는
`over` 상태 마우스 동작은 사용하지 않고 `over` 상태에 적용된 이미지만을 코드에서 사용하기 위함입니다.
토글 상태의 이미지 경로를 http:// 경로로 사용한다면 `normal` 상태의 이미지만 설정해도 됩니다.// 토글 버튼 커서 모양 설정
$self.setStyle('cursor', 'pointer');
// 토글 버튼 Element에 임시 변수를 저장
$self.scope.toggle = false;
// 토글 상태 업데이트(초기화)
update();
// 클릭 이벤트 핸들러 설정
$self.on('click', function(){
$self.scope.toggle = !$self.scope.toggle;
update();
});
function update(){
if($self.scope.toggle){
// `over` 이미지 불러올때 생성된 Asset UID
$self.api.source('asset-173d0e08-0197-4c74-9884-5a68dea47941');
}else{
// `normal` 이미지 불러올때 생성된 Asset UID
$self.api.source('asset-dcaf5929-38e8-43cc-bbc5-07f2109a1b7b');
}
}function update(){
// 이미지 Element 찾기
var image = $self.children('element-5445d04c-6129-494b-90cd-e0c967206f27');
if($self.scope.toggle){
// `over` 이미지 불러올때 생성된 Asset UID
$self.api.source('asset-173d0e08-0197-4c74-9884-5a68dea47941');
// 이미지 보이기
image.show();
}else{
// `normal` 이미지 불러올때 생성된 Asset UID
$self.api.source('asset-dcaf5929-38e8-43cc-bbc5-07f2109a1b7b');
// 이미지 감추기
image.hide();
}
}