0

私はここに別のウェブサイトへのショートカット(「タイル」)があるサイトを持っていました。

これで、「タイル」の位置をCookieに保存できるようにするスクリプトができました。これにより、ユーザーが後日Webサイトに戻ったときに、タイルの配置が保存されます。

そのスクリプトは次のとおりです。

$(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');
    });
});

これで、以前にアクセスせずに最初にWebサイトをロードすると、タイルはすべて、幅5タイル、高さ2タイルのグリッドに配置されます。

ボタンをクリックするEditと、タイルはドラッグ可能でサイズ変更可能になります。

したがって、新しいDoneボタンをクリックしてブラウザウィンドウを終了し、新しいブラウザウィンドウでWebサイトに戻ると、位置は保存されますが(これも混乱することがあります)、ある種の「非表示」リンクがあります。残ったタイルの元のグリッドを形成します。

なぜこうなった。たとえば、元の編集で、左上のGoogleタイルを元の位置から移動し、YouTubeタイルの下に配置したとします。

次に、戻ってきて、Googleタイルがあったブラウザウィンドウ上の位置にマウスを合わせると、まだそこにあるかのようにクリックできます。pointer編集モードでないときにリンクにカーソルを合わせるとカーソルが表示されるようにCSSを設定しているので、これは簡単にわかります。

リンクを元の位置から削除する方法はありますか?

4

2 に答える 2

1

firebug && firefoxを使用していますか?コンソールのfirebugで見ることができるように、内部にアンカータグがあるいくつかのli要素があり、それを移動すると何が残るのでしょうか。したがって、おそらくそれらはcssまたは以前のどこかで定義されています。

見てください: ここに画像の説明を入力してください

ワイドスクリーンなので画像のサイズを変更しました。

于 2011-01-27T22:19:51.367 に答える
0

それがそれをしている理由は、あなたがドラッグするために使用されているdiv内部を持っているからのように見えます。li代わりに、ドラッグ可能なオブジェクトとして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とクラス.tileliタグに配置します

それを回転させて、それが機能するかどうかを確認します。

于 2011-01-27T22:16:19.857 に答える