나는 내 자신의 CSS와 Jquery로 토글 체크 박스를 만들고 있는데, 실제로 내 안의 상자가 왼쪽에서 오른쪽으로 그리고 오른쪽에서 왼쪽으로 onclick 이벤트로 슬라이드하고 싶을뿐만 아니라 변경하기를 원한다. 텍스트는 예에서 아니오로, 아니오에서 예로 텍스트가 표시됩니다.이 체크 박스를 작동시키는 방법
내 CSS 파일은 다음과 같습니다
.outer-box{
background:green;
padding:5px;
width:50px;
height:20px;
}
.inner-box{
background:blue;
padding: 2px;
width:17px;
height:17px;
display:inline;
}
JS 파일은과 같습니다
$(document).ready(function(){
$('.outer-box').click(function(){
var value = $('.outer-box').attr('id');
alert(value);
if(value === 'right-box'){
// alert(value+" -- ");
//$('.outer-box').text('N');
$('.inner-box').css('float','left');
$('.outer-box').text('N');
$('.outer-box').removeAttr('id');
$('.outer-box').attr('id','left-box');
}else if(value === 'left-box'){
$('.inner-box').css('float','right');
$('.outer-box').text('Yes');
$('.outer-box').removeAttr('id');
$('.outer-box').attr('id','right-box');
}
});
});
그리고 내 HTML 파일은 다음과 같습니다
<!DOCTYPE html>
<html>
<title>Feed back Form</title>
<head>
<link rel="stylesheet" type="text/css" href="self.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script type="text/javascript" src="self.js"></script>
</head>
<body>
<div class="outer-box" id="right-box" > Yes
<div class="inner-box" style="float:right;"></div>
<div style="clear: both;"></div>
</div>
</body>
</html>
가 내 체크 박스 버튼이 원하는 이 같은 :
http://codepen.io/CreativeJuiz/pen/zqKtp 아무도 나를 도울 수
내가 만든 [jsFiddle] (http://jsfiddle.net/kF4QL/) 사람들이 실험을 할 수 있도록 코드를 다시; 도움이된다고 생각되면 질문을 수정하여 자유롭게 포함 시키십시오. – DaveParsons
게시 한 펜을 사용하지 않는 이유는 무엇입니까? 아니면 더 나은 브라우저 지원을 원하십니까? http://caniuse.com/#feat=css-transitions –
바닐라 JS에서 일하는 것을 좋아하는 사람들을 위해 [여기는 바닐라 JS 버전입니다] (http://jsfiddle.net/KLe6B/) – Albzi