jquery简单模型视图问题
我正在尝试在模型视图的帮助下制作小照片库。但是,当我单击照片时,模型视图会打开并显示照片,但也会从照片库中删除它。我使用附加在模型 viev 用户信息上创建。
<div class="userList">
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/1.jpg" /></div>
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/2.jpg" /></div>
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/3.jpg" /></div>
</div>
<div id="popup_name" class="popup_block">
<div id="userPhoto"></div>
<div id="description"></div>
</div>
这是我的 .js 文件
$(document).ready(function(){
$(".userList").children().each(function(idy) {
var $this =$(this);
$(this).hover(function () {
var $this = $(this);
$this.stop().animate({'opacity':'1.0'},200);
},function () {
var $this = $(this);
$this.stop().animate({'opacity':'0.4'},200);
}).bind('click',function(){
var $theImage = $(this);
var popID = $(this).attr('rel');
var popURL = $(this).attr('href');
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1];
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="style/images/logo.png" class="btn_close" title="Close Window" alt="Close" /></a>');
$('#popup_name').append($theImage);
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
return false;
});
});
$('#popup_name > img').live('click',function(){
$this = $(this);
$('#description').empty().hide();
$this.remove();
});
$('a.close, #fade').live('click', function() {
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
});
return false;
});
});
I am trying to make little photo gallery with help of model view. But when I click on photo model views opens and shows photo but also it deletes it from photo gallery.I used append to create on model viev user information.
<div class="userList">
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/1.jpg" /></div>
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/2.jpg" /></div>
<div class="user" href="#?w=500" rel="popup_name"> <img src="style/images/category/3.jpg" /></div>
</div>
<div id="popup_name" class="popup_block">
<div id="userPhoto"></div>
<div id="description"></div>
</div>
this is my .js file
$(document).ready(function(){
$(".userList").children().each(function(idy) {
var $this =$(this);
$(this).hover(function () {
var $this = $(this);
$this.stop().animate({'opacity':'1.0'},200);
},function () {
var $this = $(this);
$this.stop().animate({'opacity':'0.4'},200);
}).bind('click',function(){
var $theImage = $(this);
var popID = $(this).attr('rel');
var popURL = $(this).attr('href');
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1];
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="style/images/logo.png" class="btn_close" title="Close Window" alt="Close" /></a>');
$('#popup_name').append($theImage);
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
return false;
});
});
$('#popup_name > img').live('click',function(){
$this = $(this);
$('#description').empty().hide();
$this.remove();
});
$('a.close, #fade').live('click', function() {
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
});
return false;
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的情况下调用
.append()
实际上会移动 图像,这就是您所看到的:相反,您想附加一个副本,因此使用
.clone()
或.clone(true )
在这里(因为绑定了事件处理程序),如下所示:如果您确实想要来自
.hover()
在#popup_name
副本中调用,使用.clone(true)
,但我以为你不希望在这里出现这样的情况。Calling
.append()
in your situation will actually move the image, which is what you're seeing with this:Instead you want to append a copy, so use
.clone()
or.clone(true)
here (since there are event handlers bound), like this:If you do want the behavior from that
.hover()
call in the#popup_name
copy, use.clone(true)
, but I assumed you didn't want that here.