javascript/php图像定位系统的问题

发布于 2024-08-18 22:58:46 字数 2983 浏览 2 评论 0原文

我正在开发一个项目,涉及在虚拟客厅中移动产品,我有以下功能

保存产品位置

和那么函数如下:

`
function sendxandy(productAmount)
{
       if (productAmount == 1)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y;
       }
       if (productAmount == 2)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y;
       }
       if (productAmount == 3)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y;
       }
       if (productAmount == 4)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y + 
   "&xfour= " + dd.elements.image4.x + "&yfour=" + dd.elements.image4.y;
       }
       if (productAmount == 5)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y + 
   "&xfour= " + dd.elements.image4.x + "&yfour=" + dd.elements.image4.y +
   "&xfive= " + dd.elements.image5.x + "&yfive=" + dd.elements.image5.y;
}
`

函数继续像这样一直到图像 10。所以你可以看到图像的坐标保存在 URL 中,以便我可以在 php 中访问它们,我的下一个函数是这个

将图像向后移动

在这里我有这个(moveTo 变量是某些的 php 变量)原因是此显示器无法打印代码,而且 moveTo 也是由第二个脚本提供的另一个函数):

`function moveProduct(moveAmount)
{
    if (moveAmount == 1)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        }
    }
    if (moveAmount == 2)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        dd.elements.image2.moveTo(, );
        }
    }
    if (moveAmount == 3)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        dd.elements.image2.moveTo(, );
        dd.elements.image3.moveTo(, );
        }
    }

` 现在我知道我的循环结构太糟糕了:)但请耐心等待。发生的事情发生在 moveProduct 函数内部,无论最后一个 if“moveAmount == ”是什么,那么图像只会被重新定位到该数字。例如,如果我将功能设置为上述,则只会记住三个图像,不是一个或两个,或者四个或五个,而是三个。我实际上有 10 个项目,所以我为 10 个项目设置了上述功能,并且只会记住 10 个图像。当我在页面上没有 10 个项目时运行 moveProduct 函数时,什么也没有发生,就像我加载一张图像、移动它、单击保存一样,一切看起来都很好,但是当我将其移回记住的坐标时,什么也没有发生。

请帮助任何建议,我们将不胜感激

I am working on a project which involves moving products around a virtual living room, I have the following function


<a href="javascript:void(0)" onclick="sendxandy( <? echo $_SESSION['numberOfProducts']; ?> )">Save Positions of Products</a>

and then the function is as follows:

`
function sendxandy(productAmount)
{
       if (productAmount == 1)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y;
       }
       if (productAmount == 2)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y;
       }
       if (productAmount == 3)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y;
       }
       if (productAmount == 4)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y + 
   "&xfour= " + dd.elements.image4.x + "&yfour=" + dd.elements.image4.y;
       }
       if (productAmount == 5)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y + 
   "&xfour= " + dd.elements.image4.x + "&yfour=" + dd.elements.image4.y +
   "&xfive= " + dd.elements.image5.x + "&yfive=" + dd.elements.image5.y;
}
`

and the function continues just like this up to image 10. so as you can see the coordinates of the image are saved in the URL so that I can access them in php, my next function is this

<a class="code" href="javascript:void(0);" onclick="moveProduct(<? echo $_SESSION['numberOfProducts']; ?>)">Move Images Back</a>

and inside here i have this (the moveTo variables are php variables for some reason this display can't print the code, also the moveTo is another function which is provided by a second script):

`function moveProduct(moveAmount)
{
    if (moveAmount == 1)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        }
    }
    if (moveAmount == 2)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        dd.elements.image2.moveTo(, );
        }
    }
    if (moveAmount == 3)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        dd.elements.image2.moveTo(, );
        dd.elements.image3.moveTo(, );
        }
    }

`
now i know my loop structure is god awful :) but please bear with me. whats happens is inside the moveProduct function, whatever the last if "moveAmount == " is, then images will only be relocated at that number. for example if I have the function set as above only three images will be remembered, not one or two, or four or five, but three only. i actually have ten items so i have the above functions set up for 10 items, and ONLY 10 images will be remembered. When i run the function moveProduct when theres not 10 items on the page, nothing happens at all like I'll load one image, move it, click save, everything looks fine but when i move it back to remembered coordinates nothing happens.

please help any advice would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甲如呢乙后呢 2024-08-25 22:58:46

嘿,我发现了,php 变量返回空白值,这使得 js 函数完全失败:)

hey i figured it out, the php variables were returning blank values which made the js function fail entirely :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文