0

我有一个网站在这里与快捷键(“瓷砖”)不同的网站here即使在用jQuery“移动”之后,HTML链接仍然存在?

现在,我有一个脚本,允许将“tiles”的位置存储到cookie中,以便当用户稍后返回到网站时,它们的拼贴放置将被保存。

这里是一个脚本:

$(document).ready(function() { 
    //we have a hidden field which knows if the tiles are editable (1) or not (2) now just 
    // let's make sure it is initiated with zero value because the startup state of 
    // button will be "Edit" 
    $("#editable").val('0'); 
    // loop through the tiles by class 
    $('.tile').each(function() { 
     // get the positions from cookies 
     var toppos = $.cookie('uiposy' + $(this).attr('id')); 
     var leftpos = $.cookie('uiposx' + $(this).attr('id')); 
     // apply saved positions 
     $(this).css('top', toppos + 'px'); 
     $(this).css('left', leftpos + 'px'); 
     // get the sizes from cookies 
     var sizew = $.cookie('uisizew' + $(this).attr('id')); 
     var sizeh = $.cookie('uisizeh' + $(this).attr('id')); 
     // apply saved sizes 
     $(this).css('width', sizew + 'px'); 
     $(this).css('height', sizeh + 'px'); 
    }); 
    // set the tiles as draggable 
    $('.tile'). 
    draggable({ 
     containment: '#content', 
     scroll: false, 
     // watch out for drag action 
     stop: function (event, ui) { 
      // store x/y positions in a cookie when they're dragged 
      $.cookie('uiposx' + $(this).attr('id'), ui.position.left, { 
       path: '/', 
       expires: 7 
      }); 
      $.cookie('uiposy' + $(this).attr('id'), ui.position.top, { 
       path: '/', 
       expires: 7 
      }); 
     } 
    }); 
    // set the tiles as resizable 
    $('.tile').resizable({ 
     maxHeight: 200, 
     maxWidth: 200, 
     minHeight: 100, 
     minWidth: 100, 
     // watch out for resize action 
     stop: function (event, ui) { 
      // store width/height values in a cookie when they're resized 
      $.cookie('uisizew' + $(this).attr('id'), ui.size.width, { 
       path: '/', 
       expires: 7 
      }); 
      $.cookie('uisizeh' + $(this).attr('id'), ui.size.height, { 
       path: '/', 
       expires: 7 
      }); 
     } 
    }); 
    // make resiable and draggable disabled on start 
    $(".tile").resizable("option", "disabled", true).removeClass('ui-state-disabled'); 
    $(".tile").draggable("option", "disabled", true).removeClass('ui-state-disabled'); 
    // function to run when the editButton is clicked 
    $('#editButton').click(function() { 
     // store our "state" in boolean form. 
     var state = ($("#editable").val() == 0) ? false : true; 
     // state is true, this means we will disable the tiles. 
     // make the button text "edit" and change the hidden #editable field value to "0" 
     if (state) { 
      $("#editable").val('0'); 
      $(this).val('Edit'); 
      $('.tile').css('cursor', 'pointer'); 
     } 
     // state is true, this means we will enable the tiles. 
     // make the button text "Done" and change the hidden #editable field value to "1" 
     else { 
      $("#editable").val('1'); 
      $(this).val('Done'); 
      $('.tile').css('cursor', 'move'); 
     } 
     // apply the state to tiles. also remove the ui-state-disabled class to make sure they're not faded. 
     $(".tile").resizable("option", "disabled", state).removeClass('ui-state-disabled'); 
     $(".tile").draggable("option", "disabled", state).removeClass('ui-state-disabled'); 
    }); 
}); 

现在,在第一次加载以前没有访问该网站,瓦片都对准一个网格5瓦宽,2瓦高。

单击Edit按钮后,图块可拖动并调整大小。

因此,在点击新的Done按钮后,退出浏览器窗口,然后在新的浏览器窗口中返回到网站,位置被保存(有时也会出现乱码),但有“隐形“各种各样的链接,遗留下来形成瓷砖的原始网格。

为什么会发生这种情况。例如,假设您在原始编辑中将左上方的Google磁贴从原始位置移开,并将其放在YouTube磁贴下方。

然后,当您回来时,将鼠标悬停在Google平铺过去的浏览器窗口上的位置上时,您仍然可以点击,就好像它仍在那里一样。你可以很容易地说出这一点,因为我将CSS设置为在不处于编辑模式时悬停在链接上时显示一个pointer光标。

有没有办法,链接可以从他们的原始位置删除?

+2

为什么你的示例代码中的所有注释都缺少````! – 2011-01-27 22:08:09

+1

对不起!感谢帕特里克解决这个问题! – Qcom 2011-01-27 22:10:21

回答

1

你用萤火虫吗& & firefox?因为我可以在控制台中看到萤火虫,你有一些内部有锚标签的元素,这就是你在移动时留下的东西!所以可能他们定义在CSS或从以前的某个地方。

看看: enter image description here

我调整后的图像,因为我有宽屏幕。

0

它看起来像这样做的原因是因为li内部的div被用于拖动。您应该将LI标签作为可拖动对象。这样它也会拖动锚点。

所以渲染时你的HTML应该类似于此:

<ul> 
    <li id="google" class="tile ui-draggable ui-resizable ui-resizable-disabled ui-draggable-disabled" style="left: 116px; top: 119px; cursor: pointer; " aria-disabled="true"> 
     <a href="http://www.google.com" target="_blank"> 
     <div> 
     <p>Google</p> 
      <div class="ui-resizable-handle ui-resizable-e"></div><div class="ui-resizable-handle ui-resizable-s"></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 1001; "></div></div> 
     </a> 
    </li> 
</ul> 

所以把ID和对li标记的类.tile

给一个旋转,看看它是否工作。

相关问题