简体   繁体   English

如何在不重新加载页面的情况下动态交换图像

[英]How to dynamically swap images without reloading the page

I want to create a scroll horizontal for my product page, I have done it in the past, so i have an idea on how to proceed, but this time I want the image clicked to be a bigger size for example 600x600 while all the other images on the bottom of that one with the size 100x100. 我想为我的产品页面创建水平滚动,我过去已经做过,所以我对如何进行操作有一个想法,但是这次我希望图像单击得更大一些,例如600x600,而其他所有图像该图片底部的图片,尺寸为100x100。 Have an arrow left right on the side of the big image, and if the arrow is pressed left/right swap that big picture with the previous/next one from the ones in the small size 100x100. 在大图片的一侧向右箭头,如果向左/向右按箭头,则将大图片与尺寸为100x100的小图片中的上一张/下一张交换。 Those images are set using php as they are in the server, this is the part that im finding hard aswell I dont know how I would use javascript to alter the images from the php file. 这些图像是使用php设置的,就像它们在服务器中一样,这是即时消息很难找到的部分,我不知道如何使用javascript来更改php文件中的图像。

PHP code to get the images PHP代码获取图像

    $imgSet = "<img src='../ProductImages/$pID.jpg' class='image' onclick='openNav()'>";
    $imgZoom = "<img src='../ProductImages/$pID.jpg' width='600px' height='600px'>";
    $pInfo = "nothing for now";
    $pDetails = $row['PROD_DETAILS'];

    $sql = ("SELECT * FROM CHILD_IMG WHERE PROD_ID = '$pID';");
    $getQuery = $connection->query($sql);
    while($row = $getQuery->fetch_array()){
        $childID = $row['ID'];
        $parentID = $row['PROD_ID'];
        $childName = $parentID . "_".$childID.".jpg";
        $childImg .= "<img src='../ProductImages
        /ChildImages/$childName' class='imgBotSize' onclick='openNav()'>";
        Child images all the ones on the bottom of the big image
    }

Javascript 使用Javascript

 function openNav() { document.getElementById("flow").style.height = "100%"; } function closeNav() { document.getElementById("flow").style.height = "0%"; } 

HTML HTML

 <div id="flow" class="overlayImgContainer"> <a class="closebtn" onclick="closeNav()">&times;</a> <div class="overlay-img-content"> <a><?php echo $imgZoom;?></a> <div class="imgSlideGroup"> <a><?php echo $childImg;?></a> </div> </div> <div class="arrowBtn" style="right: 40px"> <img src="../arrow-right-white.png" width="70px" height="120px"> </div> <div class="arrowBtn" style="left: 40px"> <img src="../arrow-left-white.png" width="70px" height="120px"> </div> </div> 

If you have HTML like below 如果您有如下所示的HTML

            <div class="leftArrow"></div>
            <div>
              <img src="../smaller.jpg" class="selectedImage">
            </div>
            <div class="rightArrow"></div>

And in JS you can select the clicked image and reset the url to bigger image and change the style of the image as below. 在JS中,您可以选择单击的图像并将URL重置为更大的图像,然后按如下所示更改图像的样式。

                var selectedImage =  document.querySelector('.selectedImage');
                selectedImage.onclick = function(){
                selectedImage.src = '../bigger/jpg';
                selectedImage.style.height = '400px';
                selectedImage.style.width = '300px';
            }

Hope this sample code will give some hint 希望此示例代码能给您一些提示

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

相关问题 如何在不重新加载页面的情况下动态更改jquery移动页面主题? - How to dynamically change jquery mobile page theme without reloading the page? 动态渲染模板而无需重新加载页面 - Dynamically render template without reloading page 加载上一个或下一个图像而无需重新加载页面 - Load previous or next images without reloading page 如何在点击时交换网格中的元素而不重新加载DOM - How swap elements in grid on click without reloading DOM 如何在不重新加载页面的情况下更改页面 url - How to change the page url without reloading the page 如何在不重新加载整个页面的情况下使用rails和Ajax渲染新上传的图像? - How to render newly uploaded images with rails and Ajax without reloading the whole page? 动态显示用户选择类别的帖子,无需重新加载页面 - dynamically display posts of a user-chosen category without reloading page 刷新 DIV,无需重新加载页面即可动态打印文本文件 - Refresh DIV which prints a text file dynamically without reloading page ajax:如何在不重新加载页面的情况下发布消息? - ajax: How to post a message without reloading the page? 如何在不重新加载整个页面的情况下重新加载div? - How to reload a div without reloading the entire page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM