Jquery 如何制作链接以缩放图片
我目前有一个很好的脚本 当我单击图像时,缩放功能工作 但我需要创建一个单独的链接来缩放 任何建议Jquery 如何制作链接以缩放图片,jquery,image,zooming,Jquery,Image,Zooming,我目前有一个很好的脚本 当我单击图像时,缩放功能工作 但我需要创建一个单独的链接来缩放 任何建议 jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); this.css("left", ( $(window).
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
$(document).ready(function() {
$("#profile_pict_lifesign img").click(function(e){
$("#background1").css({"opacity" : "0.7"})
.fadeIn("slow");
$("#large1").html("<img src='"+$(this).parent().attr("href")+"' alt='"+$(this).attr("alt")+"' /><br/>"+$(this).attr("rel")+"")
.center()
.fadeIn("slow");
return false;
});
$(document).keypress(function(e){
if(e.keyCode==27){
$("#background1").fadeOut("slow");
$("#large1").fadeOut("slow");
}
});
$("#background1").click(function(){
$("#background1").fadeOut("slow");
$("#large1").fadeOut("slow");
});
$("#large1").click(function(){
$("#background1").fadeOut("slow");
$("#large1").fadeOut("slow");
});
});
<div id="profile_pict_lifesign"><img src="pic_memory.jpg" alt="" rel=""><a href="pic_memory.jpg">zoom</a>
<div id="profile_specs_wrap">
<div id="profile_specs_1">LIFESIGN #203</div>
<div id="profile_specs_2">Louis Tharp</div>
<div id="profile_specs_3">Born: September 20, 1964</div>
<div id="profile_specs_4">Home City & State: Indianapolis, Indiana</div>
<div id="profile_specs_5">Homeless Status: "Still Homeless"</div>
<div id="profile_specs_6">Homeless Timer: 4 Years, 3 Months, & 4 Days</div>
</div>
<div id="profile_specs_wrap2">
<div id="profile_specs_7">This is a photograph of Louis with his two loving sisters in 1969.</div>
</div>
</div>
<div id="large1"></div>
<div id="background1"></div>
jQuery.fn.center=函数(){
css(“位置”、“绝对”);
this.css(“top”,($(window.height()-this.height())/2+$(window.scrollTop()+“px”);
this.css(“left”、($(window.width()-this.width())/2+$(window.scrollLeft()+“px”);
归还这个;
}
$(文档).ready(函数(){
$(“#profile_pict_lifesign img”)。单击(函数(e){
$(“#background1”).css({“不透明”:“0.7”})
.fadeIn(“慢”);
$(“#large1”).html(“
”+$(this.attr(“rel”)+”)
.center()
.fadeIn(“慢”);
返回false;
});
$(文档)。按键(功能(e){
如果(e.keyCode==27){
美元(“#背景1”)。淡出(“缓慢”);
美元(“#大1”)。淡出(“慢”);
}
});
$(“#背景1”)。单击(函数(){
美元(“#背景1”)。淡出(“缓慢”);
美元(“#大1”)。淡出(“慢”);
});
$(“#大1”)。单击(函数(){
美元(“#背景1”)。淡出(“缓慢”);
美元(“#大1”)。淡出(“慢”);
});
});
生活标志#203
路易斯·塔普
出生日期:1964年9月20日
家乡城市和州:印第安纳州印第安纳波利斯
无家可归状态:“仍然无家可归”
无家可归者计时器:4年3个月和4天
这是一张1969年路易斯和他的两个亲爱的姐妹的照片。
尝试(此模式)
$(函数(){
$(“img”)
.在“点击”时,功能(e){
var数据=[“”);
//在新窗口做些事情
z、 document.write(“(function()”)
+“{setTimeout(函数(){”
+“如果(window.jQuery){”
+“jQuery.fn.center=window.center;”
+“jQuery('.zoom').center()},50}()”;
}, 250);
};
});
});
});
jsfiddle尝试创建新的html文档,克隆jquery,fn.center,image,从打开的文档到新的html文档,在单击事件的新窗口中打开新的html文档,在窗口加载事件回调中调用fn.center。
$(function () {
$("img")
.on("click", function (e) {
var data = ["<img class=zoom />"];
$.when(data)
.done(function (data) {
var center = function () {
this.css("position", "absolute");
this.css("top", ($(window).height() - this.height()) / 2
+ $(window).scrollTop() + "px");
this.css("left", ($(window).width() - this.width()) / 2
+ $(window).scrollLeft() + "px");
return this;
};
if ($(data[0]).is(".zoom")) {
setTimeout(function () {
var z = window.open("", "z");
z.center = center;
z.document.write(data[0]);
z.document.write("<style>" + $("style").text() + "</style>");
z.document.write("<scr"
+ "ipt>"
+ "(function() { var script=document.createElement('script');"
+ " script.src = 'http://code.jquery.com/jquery-1.11.1.min.js';"
+ "var head = document.getElementsByTagName('head')[0];"
+ "head.appendChild(script)})()</scr"
+ "ipt>");
// do stuff in new window
z.document.write("<scr"
+ "ipt>(function()"
+ "{ setTimeout(function() {"
+ "if (window.jQuery) {"
+ " jQuery.fn.center = window.center;"
+ "jQuery('.zoom').center()}},50)}())</scr"
+ "ipt>");
}, 250);
};
});
});
});