为什么show shown有没有出来
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
width: 400px;
margin: 0 auto;
}
.btn {
width: 50%;
height: 30px;
}
#box {
display: none;
margin-top: -20px;
width: 100%;
height: 200px;
background: red;
}
.transition {
-o-transition: all 0.5s;
-ms-transition: all 0.5s;
-moz-transition: all 0.5s;
-webkit-transition: all 0.5s;
transition: all 0.5s;
}
.fadeout {
visibility: hidden !important;
opacity: 1 !important;
}
.slideupdowncollapse{
height:0 !important;
}
.slideleftright{
width:0 !important;
}
</style>
</head>
<body>
<button id="btn-show" class="btn">显示</button><button id="btn-hide" class="btn">隐藏</button>
<div id="box" class=""></div>
<button class="btn">显示1</button>
<script src="js/jquery-1.7.1.js"></script>
<script src="js/transition.js"></script>
<script>
console.log(window.mt.transition.isSupport)
var transition = window.mt.transition;
//console.log(window.mt.transition.end);
function init($elem, hiddencallback) {
if ($elem.is(':hidden')) {
$elem.data('status', 'hidden')
if (typeof hiddencallback === 'function') hiddencallback();
// $elem.addClass('slideupdowncollapse')
} else {
$elem.data('status', 'shown');
}
}
function show($elem, callback) {
if ($elem.data('status') === 'show') return;
if ($elem.data('status') === 'shown') return;
$elem.data('status', 'show').trigger('show');
callback();
}
function hide($elem, callback) {
if ($elem.data('status') === 'hide') return;
if ($elem.data('status') === 'hidden') return;
$elem.data('status', 'hide').trigger('hide');
callback();
}
var silent = {
init: init,
show: function ($elem) {
// if(typeof showcallback==='function')showcallback();
show($elem, function () {
$elem.show();
$elem.data('status', 'shown').trigger('shown');
callback;
})
// if(typeof showncallback==='function')showncallback();
},
hide: function ($elem) {
hide($elem, function () {
$elem.hide();
$elem.data('status', 'hidden').trigger('hidden');
})
}
};
var css3 = {
fade: {
init: function ($elem) {
css3._init($elem,'fadeout')
},
show: function ($elem) {
css3._show($elem,'fadeout')
},
hide: function ($elem) {
css3._hide($elem,'fadeout')
}
},
slideupdown: {
init: function ($elem) {
$elem.height($elem.height());
css3._init($elem,'slideupdowncollapse');
},
show: function ($elem) {
css3._show($elem,'slideupdowncollapse')
},
hide: function ($elem) {
css3._hide($elem,'slideupdowncollapse')
}
},
slideleftright: {
init: function ($elem) {
$elem.width($elem.width());
css3._init($elem,'slideleftright');
},
show: function ($elem) {
css3._show($elem,'slideleftright')
},
hide: function ($elem) {
css3._hide($elem,'slideleftright')
}
},
fadeslideupdown: {
init: function ($elem) {
$elem.height($elem.height());
css3._init($elem,' fadeout slideupdowncollapse');
},
show: function ($elem) {
css3._show($elem,'slideupdowncollapse fadeout ')
},
hide: function ($elem) {
css3._hide($elem,'slideupdowncollapse fadeout ')
}
},
fadeslideleftright: {
init: function ($elem) {
$elem.width($elem.width());
css3._init($elem,'slideleftright fedeout');
},
show: function ($elem) {
css3._show($elem,'slideleftright fedeout')
},
hide: function ($elem) {
css3._hide($elem,'slideleftright fedeout')
}
}
};
var js = {
fade: {
show: function ($elem) {
show($elem,function(){
$elem.fadeIn(function(){
$elem.data('status','shown').trigger('shown');
})
})
},
hide: function ($elem) {
hide($elem,function(){
$elem.fadeOut(function(){
$elem.data('status','hidden').trigger('hidden');
});
});
}
},
slideupdown: {
show: function () {
},
hide: function () {
}
},
slideleftright: {
show: function () {
},
hide: function () {
}
},
fadeslideupdown: {
show: function () {
},
hide: function () {
}
}, fadeslideleftright: {
show: function () {
},
hide: function () {
}
}
};
css3._init=function($elem ,classname){
$elem.addClass('transition');
init($elem, function () {
$elem.addClass(classname);
});
};
css3._show=function($elem,classname){
show($elem, function () {
$elem.off(transition.end).one(transition.end, function () {
$elem.data('status', 'shown').trigger('shown');
})
$elem.show();
setTimeout(function () {
$elem.removeClass(classname);
}, 20);
})
};
css3._hide=function($elem,classname){
hide($elem, function () {
$elem.off(transition.end).one(transition.end, function () {
$elem.hide();
$elem.data('status', 'hidden').trigger('hidden');
});
$elem.addClass(classname);
});
}
var $box = $('#box');
//css3.fadeslideleftright.init($box);
$('#btn-hide').on('click', function () {
js.fade.hide($box);
});
$('#btn-show').on('click', function () {
js.fade.show($box)
});
// silent.init($box);
// $('#btn-show').on('click',function(){
// css3.fade.show($box)
// });
// $box.on('show shown hide hidden',function(e){
// console.log(e.type)
// })
// $box.on('show shown',function(e){
// if(e.type==='show'){
// $box.css('background','yellow')
// }else if(e.type==='shown'){
// setTimeout(function(){
// $box.css('background','')
// },1000)
// }
// })
$box.on('show shown hide hidden', function (e) {
console.log(e.type)
})
</script>
</body>
</html>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星