简体   繁体   English

如何使用另一段javascript中的img id =“ image1”在点击时弹出?

[英]How can I use an img id=“image1” from another piece of javascript to pop up on click?

I would like to make it so that when a user on the website clicks on a thumbnail it will pop up in an overlay as full size. 我要这样做,以便当网站上的用户单击缩略图时,它将以全尺寸显示在叠加中。 I have found a ton of different ways to do this when you can specify the actual image source, however I need to specify an image source out of another piece of javascript. 当您可以指定实际的图像源时,我发现了很多不同的方法来执行此操作,但是我需要从另一段JavaScript中指定图像源。

I am currently using this code to pull the product description, price, and picture URL out of a google sheet: 我目前正在使用此代码从Google表格中提取产品说明,价格和图片网址:

<!--Begin Javascript to pull Product/Price/Picture_URL Info from google sheet-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">

  // https://google,developers.appspot.com/chart/interactive/docs/spreadsheets#gid
  google.load('visualization', '1', {packages: ['corechart', 'line']});
  google.setOnLoadCallback(drawChart);

  function drawChart() {
    // Add your sheets url and range below
    var spreadsheetUrl = "https://docs.google.com/spreadsheets/d/1l6FmSuwU2E134UuxoNyRfvTw2UY_0G0q69ZwfbQy3mY/edit?range=B12:D20";
    var query = new google.visualization.Query(spreadsheetUrl);
    query.send(handleQueryResponse);
  }

  function handleQueryResponse(response) {
    var dataTable = response.getDataTable();
    // getValue(rowIndex, columnIndex)
    document.getElementById("product1").innerHTML = dataTable.getValue(0, 0);

    document.getElementById("price1").innerHTML = dataTable.getValue(0, 1);

    document.getElementById("image1").src = dataTable.getValue(0, 2);

  }

 </script>

Then I show the product thumbnails with description and price using this: 然后,我使用以下方法显示带有说明和价格的产品缩略图:

    <!--Begin Product Description/Price/Image Blocks--> 

     <div id="description1" style="position: absolute; width: 170px; height: 18px; z-index: 64; left: 390px; top: 547px">
<p id="product1" align="center"></p>
</div>
     <div id="money1" style="position: absolute; width: 170px; height: 18px; z-index: 63; left: 390px; top: 570px">
<p id="price1" align="center"></p>
</div>
    <div id="picture1" style="position: absolute; width: 160px; height: 190px; z-index: 5; left: 395px; top: 355px; right: 645px;">
<img id="image1" src="" width="162" height="192" align="center"><img>
    </div>

I'm not sure how to use the img id="image1" as the source to pop the image up larger over the top of my page. 我不确定如何使用img id="image1"作为来源来将图片弹出页面上方。

TIA! TIA!

Here is my attempt. 这是我的尝试。

Is fancybox okay? fancybox可以吗?

CodePen 密码笔

 <!--Begin Javascript to pull Product/Price/Picture_URL Info from google sheet--> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> $(document).ready(function() { $('.fancybox').fancybox(); }) // https://google,developers.appspot.com/chart/interactive/docs/spreadsheets#gid google.load('visualization', '1', { packages: ['corechart', 'line'] }); google.setOnLoadCallback(drawChart); function drawChart() { // Add your sheets url and range below var spreadsheetUrl = "https://docs.google.com/spreadsheets/d/1l6FmSuwU2E134UuxoNyRfvTw2UY_0G0q69ZwfbQy3mY/edit?range=B12:D20"; var query = new google.visualization.Query(spreadsheetUrl); query.send(handleQueryResponse); } function handleQueryResponse(response) { var dataTable = response.getDataTable(); // getValue(rowIndex, columnIndex) document.getElementById("product1").innerHTML = dataTable.getValue(0, 0); document.getElementById("price1").innerHTML = dataTable.getValue(0, 1); document.getElementById("image1").src = dataTable.getValue(0, 2); document.getElementById("img1").href = dataTable.getValue(0, 2); } </script> <!--Begin Product Description/Price/Image Blocks--> <div id="description1" style="position: absolute; width: 170px; height: 18px; z-index: 64; left: 390px; top: 547px"> <p id="product1" align="center"></p> </div> <div id="money1" style="position: absolute; width: 170px; height: 18px; z-index: 63; left: 390px; top: 570px"> <p id="price1" align="center"></p> </div> <div id="picture1" style="position: absolute; width: 160px; height: 190px; z-index: 5; left: 395px; top: 355px; right: 645px;" data-role> <a id="img1" class="fancybox" rel="group" href=""> <img id="image1" src="" width="162" height="192" align="center"> <img> </a> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在属性上添加“ id” <img> 当我单击图像时? - How can i add attribut “id” on <img> when i click the image? 如何使用javascript“单击”没有ID或名称的按钮? - How can I use javascript to “click” a button that has no id or name? 如何从数组列表/javascript中弹出图像 - How to pop-up an image from array list /javascript 我可以创建不使用Javascript的HTML弹出窗口吗? 或者我可以将Javascript放入 <body> 部分? - Can I create an HTML pop up that do not use Javascript? or can I put the Javascript into the <body> section? 如何通过点击带有javascript的图像返回img.src? - How can i return img.src by clicking on an image with javascript? 我想创建一个flickr画廊,当我单击图片显示时,弹出带有图片及其标签,标题,照片的证件 - I want create a flickr gallery and when i click on image show pop up with the image and its tags, tittle, photo id 如何从javascript中的API中提取图像ID? - How can I extract image id from an API in javascript? 如何使用cookie来防止弹出彩盒? - How can I use cookies to prevent a pop up with colorbox? 我该如何使用<img>在 Android 上使用本地图像? - How can I use <img> with a local image on Android? 如何使用从PHP到JavaScript的输入Box ID? - How can I use input Box ID from PHP to JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM