[英]jquery Click event doesn't fires
I'm not sure my closeContent();
我不确定我的
closeContent();
doesn't fire. 不射击。 I trying to load something and then close it and animate stuff with css3.
我试图加载某些内容,然后将其关闭并使用css3对其进行动画处理。
also I'd like to show the loader but not sure its the best approach. 我也想展示装载机,但不确定其最佳方法。
$('.show-content').on('click', function (e) {
e.preventDefault();
openContent();
});
$('#load-content .prev').on('click', function (e) {
e.preventDefault();
closeContent();
});
function openContent(){
$('#load-content').load('../views/product-page.html');
$('.container').addClass('loaded', function () {
//setTimeout(function () {
$('#load-content').html('<img id="loader" src="../assets/images/bx_loader.gif">');
$('#loader').css({border: '0', position: 'absolute', top: '26px', left: '50%', 'margin-left': '-26px'});
console.log('loading???')
//}, 60000);
});
$("#load-content").bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function () {
$(this).addClass('animate');
var body = $("body,html");
body.animate({
scrollTop: 0
}, 800);
});
}
function closeContent(){
var Loaded = !$(this).closest('.container').hasClass('.loaded');
if (!Loaded) {
$('.animate').removeClass('animate');
$("#load-content").bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function () {
$('.loaded').removeClass('loaded');
$('#show-content').remove();
});
}
}
You need to pass this
你需要通过
this
$('#load-content .prev').on('click', function (e) {
e.preventDefault();
closeContent(this);
});
then in the function 然后在功能
function closeContent(ele){
var Loaded = !$(ele).closest('.container').hasClass('.loaded');
if .prev
element is dynamically added use event delegation. 如果
.prev
元素是动态添加的,则使用事件委托。
$('#load-content').on('click','.prev',function(e){
e.preventDefault();
closeContent(this);
});
or 要么
$(document).on('click','#load-content .prev',function(e){
e.preventDefault();
closeContent(this);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.