开发者

jQuery Position() not run on $(document).ready()?

i am using the jQueryUI Position Utilities, but i don't know why it not run on $(document).ready(), if i use firebug and execute the position(); again manually, it work fine.

Update: I try that code only not work on IE8, it work on firefox and chrome.

The code on : http://jsbin.com/owoya3/edit

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
    <style type="text/css">
        #Parent
        {
             width: 300px; 
             background-color: #999; 
             border: 1px solid #aaa;
        }
        #Parent  tr  td 
        {
            width: 60px; 
            height: 60px;
             text-align: center; 
             border: 1px solid #aaa;
        }
        div.positionable
        {
            width: 60px;
            height: 60px;
            position: absolute;
            display: block;
            right: 0;
            bottom: 0;
            background-color: #bcd5e6;
            text-align: center;
        }
    </style>
    <script type="text/javascript">

        function position() {
            $("#BoxA").position({
                of: $("#CellA"),
                my: 'left top',
                at: 'left top',
                offset: '开发者_开发百科0 0'
            });
        }


        $(document).ready(function () {
            $(".positionable").css("opacity", 0.5);
            position();
        });
    </script>
    <title></title>
</head>
<body>
    <table id="Parent">
        <tr>
            <td id="CellA">A</td>
            <td id="CellB">B</td>
        </tr>
    </table>
    <div id="BoxA" class="positionable">
        <p>A(2)</p>
    </div>
    <div id="BoxB" class="positionable">
        <p>B(2)</p>
    </div>
</body>
</html>


The problem is fixed, maybe bug of IE or jquery, but in quick , i do it in a dirty way, i call position() twice can be fix.

    $(document).ready(function () {
        position();
        position(); //YES, 2 times.
    });


Instead of using $(document).ready use $(window).load The little difference between them makes actually the difference. You can search depper info but you'll solve your issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜