Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示图像onclick javascript_Javascript_Asp.net_Jquery_Vb.net_Fancybox - Fatal编程技术网

显示图像onclick javascript

显示图像onclick javascript,javascript,asp.net,jquery,vb.net,fancybox,Javascript,Asp.net,Jquery,Vb.net,Fancybox,单击tumbnail版本的图像后,如何加载原始图像? 我将ASP.NET与javascript结合使用 原始图像很大,因此在服务器端进行了缩放。这使得站点加载速度更快。但不知何故,这两个版本(原始和tumbnail)的图像都被下载了 我正在尝试只下载tumbnail版本的图像。当用户点击图像时,我想显示原始图像 我怎样才能做到这一点呢?下面针对每个缩略图的Html应该可以做到这一点 <a href="[url to original image]" target="_blank" id="

单击tumbnail版本的图像后,如何加载原始图像? 我将ASP.NET与javascript结合使用

原始图像很大,因此在服务器端进行了缩放。这使得站点加载速度更快。但不知何故,这两个版本(原始和tumbnail)的图像都被下载了

我正在尝试只下载tumbnail版本的图像。当用户点击图像时,我想显示原始图像


我怎样才能做到这一点呢?

下面针对每个缩略图的Html应该可以做到这一点

<a href="[url to original image]" target="_blank" id="thumbnail_link">
  <img src="[url to thumbnail image]" alt="Click to see the full image" />
</a>

不要忘了包括jquery和fancybox js文件。

我认为您必须先显示缩略图,然后单击需要在新的弹出窗口中打开原始图像。您可以使用下面给出的代码来实现这一点-

<SCRIPT LANGUAGE="JavaScript">
function openImage(imageFile){
windowOpen=window.open("",'Open','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=1,width=420,height=420');
windowOpen.document.writeln("<head><title>Image</title></head><body>");
windowOpen.document.writeln('<img src=http://www.mysite.com/' + imageFile + 'border=1>');
windowOpen.document.writeln("</body></html>");
}
</SCRIPT>

函数openImage(imageFile){
windowOpen=window.open(“,'open','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizeable=1,width=420,height=420”);
windowOpen.document.writeln(“图像”);
windowOpen.document.writeln(“”);
windowOpen.document.writeln(“”);
}
然后在单击缩略图时调用这个openImage()方法。
您可以将imageFile作为参数传递给函数。

听起来您在HTML中引用了两个图像,即使其中一个图像在视图中隐藏,因此浏览器会同时请求这两个图像。您需要做的是使用JavaScript从头创建完整大小的
标记,然后将其添加到HTML中的相关位置。一旦将全尺寸图像添加到DOM中,浏览器将加载该图像。

对于fancy box,只需

<a id="single_image" href="image_big.jpg"><img src="image_small.jpg" alt=""/></a>

问候,, Andy.

HTML代码:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <title> - jsFiddle demo</title> 
  <script type='text/javascript' src='http://identify.site88.net/showimage.js'></script>
  <style type='text/css'>
       #test{
        display:none
        }
       #blackout {
       width:50%;
       position:absolute;
       background-color: rgba(0, 0, 0, .5);
       display: none;
       z-index: 20;
       }
       .modal {
       margin: auto;
       }
       #close {
       color: white;
       font-weight: bold;
       cursor: pointer;
       }   
  </style>
    <script type='text/javascript'>
    $(window).load(function(){
    $('img').click(function () {
        var img = $(this).clone().addClass('modal').appendTo($('#blackout'));
        $('#blackout > #close').click(function () {
            $('#blackout').fadeOut(function () {
                img.remove();
            });
        });
        $('#blackout').fadeIn();
    });
    });  

    $(window).load(function(){
    $('#close2').hide();
    $('span').click(function () {
        $('#test').show();
        $('#close2').show();
        $('#txtsp').hide();
        $('#blackout2 > #close2').click(function () {
            $('#blackout2').fadeOut(function () {
                $('#test').hide();
                $('#txtsp').show();
                $(this).css({
                    "text-decoration": ''
                });
            });
        });
        $('#blackout2').fadeIn();
    });
    });  
    </script>
</head>
<body>
    <div id="blackout2"><div id="close2" >Close</div></div><img id="test" src="http://data.vietinfo.eu/News//2012/10/16/179281/1350402084.7404.jpg"/> <span id="txtsp">Click here to show image</span>
    <br /><br />
    <div id="blackout"><div id="close">Close</div></div><div style="width: 50px; height: 50px;"><img width="100%" src="http://dantri.vcmedia.vn/Uploaded/2009/06/02/hh02066.jpg" /></div>
</body>
</html>

-JSFIDLE演示
#试验{
显示:无
}
#停电{
宽度:50%;
位置:绝对位置;
背景色:rgba(0,0,0,5);
显示:无;
z指数:20;
}
.莫代尔{
保证金:自动;
}
#接近{
颜色:白色;
字体大小:粗体;
光标:指针;
}   
$(窗口)。加载(函数(){
$('img')。单击(函数(){
var img=$(this.clone().addClass('modal').appendTo($('#blackout'));
$(“#断电>#关闭”)。单击(函数(){
$(“#断电”).fadeOut(函数(){
img.remove();
});
});
$('停电').fadeIn();
});
});  
$(窗口)。加载(函数(){
$('#close2').hide();
$('span')。单击(函数(){
$('#test').show();
$('#close2').show();
$('#txtsp').hide();
$(“#停电2>#关闭2”)。单击(函数(){
$('#blackout2')。淡出(函数(){
$('#test').hide();
$('#txtsp').show();
$(this.css)({
“文本装饰”:“
});
});
});
$('#blackout2').fadeIn();
});
});  
关闭单击此处以显示图像


接近

您可以用服务器端已缩放的图像替换标记span。

可以工作,但不需要弹出窗口,因为图像可以加载到覆盖分区中。您好,我正在fancybox中显示图像,这是javascript。www.fancybox.net.@Yustme-不知道fancybox的花花公子,但我的答案中的代码是一个javascript方法。不确定您将如何在fancybox中使用此方法。但它会在鼠标单击事件后添加吗?因为现在它正在下载两者。这是不必要的。确切地说,在鼠标点击时呈现较大图像的HTML,不要只是在页面加载时将其隐藏在HTML中,然后使用JS稍后显示,因为浏览器将下载它。另外,只是想一想,您是否尝试过使用jQuery?它非常适合你所做的事情,你会发现有一大堆插件可以在一个漂亮的盒子里用关闭/下一个/上一个按钮呈现完整大小的图像。只需谷歌jQuery图像库。@TimS,当点击缩略图时,上面的代码将在新窗口中显示全尺寸图像。除非他想在页面的某个层中显示完整的图像,否则我更喜欢上面的标记,因为它不依赖于java-script。fancybox js文件在哪里?用fancybox重新标记,因为这在问题的任何地方都没有提到,只在下面的评论中提到。
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <title> - jsFiddle demo</title> 
  <script type='text/javascript' src='http://identify.site88.net/showimage.js'></script>
  <style type='text/css'>
       #test{
        display:none
        }
       #blackout {
       width:50%;
       position:absolute;
       background-color: rgba(0, 0, 0, .5);
       display: none;
       z-index: 20;
       }
       .modal {
       margin: auto;
       }
       #close {
       color: white;
       font-weight: bold;
       cursor: pointer;
       }   
  </style>
    <script type='text/javascript'>
    $(window).load(function(){
    $('img').click(function () {
        var img = $(this).clone().addClass('modal').appendTo($('#blackout'));
        $('#blackout > #close').click(function () {
            $('#blackout').fadeOut(function () {
                img.remove();
            });
        });
        $('#blackout').fadeIn();
    });
    });  

    $(window).load(function(){
    $('#close2').hide();
    $('span').click(function () {
        $('#test').show();
        $('#close2').show();
        $('#txtsp').hide();
        $('#blackout2 > #close2').click(function () {
            $('#blackout2').fadeOut(function () {
                $('#test').hide();
                $('#txtsp').show();
                $(this).css({
                    "text-decoration": ''
                });
            });
        });
        $('#blackout2').fadeIn();
    });
    });  
    </script>
</head>
<body>
    <div id="blackout2"><div id="close2" >Close</div></div><img id="test" src="http://data.vietinfo.eu/News//2012/10/16/179281/1350402084.7404.jpg"/> <span id="txtsp">Click here to show image</span>
    <br /><br />
    <div id="blackout"><div id="close">Close</div></div><div style="width: 50px; height: 50px;"><img width="100%" src="http://dantri.vcmedia.vn/Uploaded/2009/06/02/hh02066.jpg" /></div>
</body>
</html>