Created
January 2, 2014 11:38
-
-
Save hidoos/8218002 to your computer and use it in GitHub Desktop.
A Pen by hidoos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://code.jquery.com/jquery-2.0.0.js"></script> | |
<h3>pure javascript</h3> | |
<div class="box"></div> | |
<button class="togglebtn">play</button> | |
<h3> jquery transition </h3> | |
<div class="box"></div> | |
<button class="togglebtn">play</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* native js control transtion */ | |
var doc = document, | |
win = window; | |
var elBoxs = doc.getElementsByClassName('box'), | |
toggleBtns = doc.getElementsByClassName('togglebtn'); | |
console.log(toggleBtns[0]); | |
var $elboxTwo = $('div:eq(1)'), | |
$toggleBtnTwo = $('.togglebtn:eq(1)'); | |
/** | |
* prue js controls transition | |
*/ | |
toggleBtns[0].onclick = function(){ | |
if(this.innerHTML === "play"){ | |
this.innerHTML = "pause"; | |
elBoxs[0].classList.add("horizTranslate"); | |
}else{ | |
this.innerHTML = "play"; | |
var computedStyle = win.getComputedStyle(elBoxs[0]); | |
var elBoxsMarginleft = computedStyle.getPropertyValue('margin-left'); | |
elBoxs[0].style.marginLeft = elBoxsMarginleft; | |
elBoxs[0].classList.remove("horizTranslate"); | |
} | |
} | |
/** | |
* jquery controls transttion | |
*/ | |
$toggleBtnTwo.on('click',function(e){ | |
console.log('cshi'); | |
if($(this).html() === "play"){ | |
$(this).html('pause'); | |
$elboxTwo.addClass('horizTranslate'); | |
}else{ | |
$(this).html('play'); | |
var marginleft = $elboxTwo.css('margin-left'); | |
console.log(marginleft); | |
$elboxTwo.css('margin-left',marginleft); | |
$elboxTwo.removeClass('horizTranslate'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.box{ | |
height:80px; | |
width:80px; | |
margin-left:10px; | |
background:blue; | |
position:relative; | |
} | |
.togglebtn{ | |
margin:10px; | |
padding:4px 10px; | |
} | |
.horizTranslate{ | |
-webkit-transition:3s; | |
transtion:3s; | |
margin-left:50%!important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在写这个列子的时候,好多次都拼写错了!注意不要拼写错误代码。