我正在使用jquery克隆功能,但我真的不明白会发生什么。 阅读文档说如果我使用clone(true),则应复制所有事件处理程序。但这种情况并没有发生。
所以,我尝试做的是一个灯箱,在里面克隆缩放效果。 Here is the site
您可以看到我试图克隆的缩放效果的大照片,然后如果您点击链接 ver mas ,您将看到灯箱效果但没有变焦。
这是点击功能,这是我做的功能:
jQuery(document).ready(function(){
var lb = '<div class="lb-cont"></div>';
jQuery(lb).prependTo('body');
jQuery('.post').each(function(){
//code and vars to center the content....
obj.on('click','.vm',function(){
var bh = jQuery('body').height();
var contenido = jQuery('.light-cont', obj).clone(true).removeClass('hide');
jQuery('.lb-cont').width(ww);
jQuery('.lb-cont').height(bh);
jQuery('.lb-cont').fadeIn('slow');
contenido.appendTo('.lb-cont');
return false;
});
)};
)};
我最后一个让它工作的意图是在我的代码中包含缩放效果,它可以正常工作,
obj.bind('click','.vm',function(){
var bh = jQuery('body').height();
var contenido = jQuery('.light-cont', obj).clone(true).removeClass('hide');
jQuery('.lb-cont').width(ww);
jQuery('.lb-cont').height(bh);
jQuery('.lb-cont').fadeIn('slow');
contenido.appendTo('.lb-cont');
//THIS IS THE ZOOM TRIGGER
jQuery('.imagess').epicZoom({});
return false;
});
但我想知道这是否正确,为什么克隆(true)和克隆(true,true)不起作用。
答案 0 :(得分:0)
$(document).ready(function () {
var lb = '<div class="lb-cont"></div>';
$(lb).prependTo('body');
$('.post').each(function () {
var obj = $(this);
var verMas = $('.vm', obj)
//medidas ventana
var ww = $(window).width();
var wh = $(window).height();
//contenedor
var contenedorInfo = $('.light-cont');
//medidas del contenedor
var lbw = contenedorInfo.width();
var lbh = contenedorInfo.height();
verMas.live('click', function () {
var bh = $('body').height();
var contenido = $('.light-cont', obj).clone(true, true).removeClass('hide');
$('.lb-cont').width(ww);
$('.lb-cont').height(bh);
$('.lb-cont').fadeIn('normal');
contenido.appendTo('.lb-cont');
var cerrar = '<div id="cerrar-cont"><div id="cerrar">X</div></div>';
$(cerrar).prependTo('.lb-cont .light-cont');
$('.imagess').epicZoom({});
var urlss = $('#facebook').attr('st_url');
stWidget.addEntry({
"service": "facebook",
"element": document.getElementById('facebook'),
"url": urlss,
"title": "sharethis",
"type": "large",
"text": "ShareThis",
"image": "http://www.softicons.com/download/internet-icons/social-superheros-icons-by-iconshock/png/256/sharethis_hulk.png",
"summary": "this is description1"
});
return false;
});
});
$('#cerrar').live('click', function (event) {
$('.lb-cont').fadeOut('normal');
});
function pos_obj(lbw, lbh, ww, wh) {
contenedorInfo.css({
'margin-left': (ww / 2) - (lbw / 2) + 'px',
'margin-top': (wh / 2) - (lbh / 2) + 'px'
});
};
pos_obj(lbw, lbh, ww, wh);
$(window).resize(function () {
ww = $(window).width();
wh = $(window).height();
lbw = contenedorInfo.width();
lbh = contenedorInfo.height();
contenedorInfo = $('.light-cont');
$('.lb-cont').width(ww);
pos_obj(lbw, lbh, ww, wh);
});
});
在你的jquery中有两三个'});'缺少一个';'缺少...检查...