首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

【跪求】JS有关问题,之前发帖失误。重发,跪求解答

2012-05-09 
【跪求】JS问题,之前发帖失误。重发,跪求解答!JScript code!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Tr

【跪求】JS问题,之前发帖失误。重发,跪求解答!

JScript code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <style type="text/css">        body {  font-size:13px; color:#222; margin:0;}        p { margin:20px; padding:0;}                #container { width:960px; margin:20px auto; position:relative; list-style:none;}        #container li { width:150px; height:100px; position:absolute; top:0; left:0;               text-align:center; border:solid 1px #aaa;               cursor:pointer;               -moz-box-shadow: 0px 0px 3px #888;               -webkit-box-shadow: 0px 0px 3px #888;               box-shadow: 0px 0px 3px #888;               -moz-border-radius:5px; -webkit-border-radius:               5px; border-radius:5px;               background:#e0e0e0 url(file:///D|/%E6%96%87%E4%BB%B6/web/%E5%A4%A7%E4%B8%89%E4%B8%8A%E5%AD%A6%E4%B9%A0%E7%9A%84%E5%AE%9E%E6%88%98/bkg.png) repeat-x scroll left top;}        #container li a { color:#222; text-decoration:none;}                      #container li.current { border:solid 1px #888; background:#f0f0f0 url(file:///D|/%E6%96%87%E4%BB%B6/web/%E5%A4%A7%E4%B8%89%E4%B8%8A%E5%AD%A6%E4%B9%A0%E7%9A%84%E5%AE%9E%E6%88%98/bkg-current.png) repeat-x scroll left top; cursor:default;}        #container li.current a { color:#0010a9; text-decoration:underline;}            </style>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>    <script type="text/javascript">        $(document).ready(function() {                        var itemWidth = $("#container li").width();            // hide 50% of each window            var itemPosition = itemWidth * 50 / 100;            // slide each window 60% if its width               var itemMove = itemWidth * 60 / 100;                    // move windows below eachother            $("#container li").each(function(i) {                $(this).attr("id", i).css("z-index", 100 - i).css("left", itemPosition * i);            });            $("#container li").click(function(e) {                var currentID = parseInt($(".current").attr("id"));                var clickedID = parseInt($(this).attr("id"));         if (currentID != clickedID) {                e.preventDefault();                    var currentZ = 99;                    var current = $(this);                    setTimeout(function() { $(".current").removeClass("current"); current.css("z-index", currentZ).addClass("current"); }, 500);                    if (clickedID > currentID) {                    var i = 1;                    for (j = clickedID - 1; j >= 0; j = j - 1) {                        $("#" + j).animate({ "left": "-=" + itemMove * (i) + "px" }, 500);                        $("#" + j).animate({ "left": "+=" + itemMove * (i) + "px" }, 300);                        i = i + 1;                    }                    var i = 1;                    setTimeout(function() {                        for (j = clickedID - 1; j >= 0; j = j - 1) {                            $("#" + j).css("z-index",currentZ - i);                            i = i + 1;                        }                    }, 500);                    }                    else {                        var i = 1;                        var total = $("#container li").length;                        for (j = clickedID + 1; j <= total; j = j + 1) {                            $("#" + j).animate({ "left": "+=" + itemMove * i + "px" }, 500);                            $("#" + j).animate({ "left": "-=" + itemMove * i + "px" }, 300);                            $("#" + j).css("z-index", currentZ - i);                        }                         /*  不知道这里为什么不加这个呢~?就可以有那个缓冲的效果呢?                         var i = 1;                         setTimeout(function() {                        for (j = clickedID + 1; j <= total; j = j + 1) {                            $("#" + j).css("z-index",currentZ - i);                            i = i + 1;                        }                    }, 500);那个表示在500毫秒之后才改变z-index,不过为什们当(clickedID > currentID)就要用这个函数而当clickedID<currentID 就不用调用这个函数了 ,当(clickedID<currentID)在不调用这个函数的情况下而也会出现500毫秒才改变z-index的效果呢?~?*/                    }                }            });        });    </script></head><body>    <ul id="container">        <li class="current"><p>This element is on the top by default</p></li>        <li><p>Go to<br /><a href="http://www.jankoatwarpspeed.com">Warp Speed</a> blog</p></li>        <li><p>Go to<br /><a href="http://www.jquery.com">jQuery</a></p></li>        <li><p>Go to<br /><a href="http://www.opera.com/mobile/">Opera Mobile</a></p></li>    </ul></body></html> 



[解决办法]
楼主能直接问现象么?实在不懂楼主的需求

不过我猜楼主是不是要这样
JScript code
var itemWidth = $("#container li").width();            // hide 50% of each window            var itemPosition = itemWidth * 50 / 100;            // slide each window 60% if its width               var itemMove = itemWidth * 60 / 100;                         var timeObj;                   // move windows below eachother            $("#container li").each(function(i) {                $(this).attr("id", i).css("z-index", 100 - i).css("left", itemPosition * i);            });            $("#container li").click(function(e) {                var currentID = parseInt($(".current").attr("id"));                var clickedID = parseInt($(this).attr("id"));         if (currentID != clickedID) {                e.preventDefault();                    var currentZ = 99;                    var current = $(this);                    setTimeout(function() { $(".current").removeClass("current"); current.css("z-index", currentZ).addClass("current"); }, 500);                    if (clickedID > currentID) {                        clearTimeout(timeObj);                        var i = 1;                        for (j = clickedID - 1; j >= 0; j = j - 1) {                            $("#" + j).animate({ "left": "-=" + itemMove * (i) + "px" }, 500);                            $("#" + j).animate({ "left": "+=" + itemMove * (i) + "px" }, 300);                            i = i + 1;                        }                        var i = 1;                        setTimeout(function() {                            for (j = clickedID - 1; j >= 0; j = j - 1) {                                $("#" + j).css("z-index",currentZ - i);                                i = i + 1;                            }                        }, 500);                    } else {                        var i = 1;                        var total = $("#container li").length;                        for (j = clickedID + 1; j <= total; j = j + 1) {                            $("#" + j).animate({ "left": "+=" + itemMove * i + "px" }, 500);                            $("#" + j).animate({ "left": "-=" + itemMove * i + "px" }, 300);                            $("#" + j).css("z-index", currentZ - i);                        }                          // 不知道这里为什么不加这个呢~?就可以有那个缓冲的效果呢?                         var i = 1;                        timeObj = setTimeout(function() {                        for (j = clickedID + 1; j <= total; j = j + 1) {                            $("#" + j).css("z-index",currentZ - i);                            i = i + 1;                        }                    }, 500);/*那个表示在500毫秒之后才改变z-index,不过为什们当(clickedID > currentID)就要用这个函数而当clickedID<currentID 就不用调用这个函数了 ,当(clickedID<currentID)在不调用这个函数的情况下而也会出现500毫秒才改变z-index的效果呢?~?*/                    }                }            }); 

热点排行