2010-12-01 38 views
0

嘿,夥計們,我通常編輯很不錯,但這次我想我會嘗試一些新的JQuery。我試圖創建一個「3D」卡片頁面(類似於:http://activeden.net/item/xml-3d-video-showcase/83740?clickthrough_id=&redirect_back=true&ref=45),但我無法定位這些元素,並且我認爲我的代碼都是錯誤的。jquery元素定位和更多

這裏的JS:

$(document).ready(function() { //perform actions when DOM is ready 
var z = 0; //for setting the initial z-index's 
    var inAnimation = false; //flag for testing if we are in a animation 
    var imgLoaded = 0; //for checking if all images are loaded 

$('.img').each(function() { 
    z++; 
    $(this).css('z-index', z); 
    imgLoaded++; 
}); 

function swapFirstLast(isFirst) { 
    if(inAnimation) return false; //if already swapping pictures just return 
    else inAnimation = true; //set the flag that we process a image 

    var processZindex, direction, newZindex, inDeCrease; //change for previous or next image 
    if(isFirst) { 
     processZindex = z; newZindex = 1; inDeCrease = 1; 
    } else { 
     processZindex = 1; newZindex = z; inDeCrease = -1; 
    } //set variables for "next" and "previous" action 

    $('.img').each(function() { //process each image 
    if($(this).css('z-index') == processZindex) { //if its the image we need to process 
    $(this).animate({ opacity: 0,top: $(this).height() + 'px' }, 'slow', function() { 
    $(this).css('z-index', newZindex) //set new z-index 
     .animate({top : '0' }, 'slow', function() { 
     inAnimation = false; //reset the flag 
     $(this).animate({ opacity: 1 }, 500); 
     }); 
    }); 
    } else { //not the image we need to process, only in/de-crease z-index 
    $(this).animate({top : '0' }, 'slow', function() { //make sure to wait swapping the z-index whe 
    $(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease); //in/de-crease the z-index by one 
    }); 
    } 
    }); 
return false; //don't follow the clicked link 
} 

$('#next a').click(function() { 
    return swapFirstLast(true); //swap first image to last position 
}); 

$('#prev a').click(function() { 
    return swapFirstLast(false); //swap last image to first position 
}); 

}); 

而這裏的HTML:

<html> 
<head> 
<style type="text/css"> 
ul { list-style: none; 
margin: 200px;} 

#pictures { position: relative; height: 408px;} 

.img { 
position: absolute; 
top: 10; 
left: 0; 
padding: 10px; 
background: #eee; 
border: 1px solid #fff; 
-webkit-transform: translate(0px, 0px) skew(0deg, 5deg); 
} 
.desc { 
max-height: 30px; 
text-align: center; 
padding: 10px 10px 0 10px; 
} 
li { 
border: 5px solid #c4c8cc; 
-moz-box-shadow: 3px 3px 10px #888; 
-webkit-box-shadow: 3px 3px 10px #888; 
padding: 200px; 
} 
</style> 
</head> 
</html> 

<div id="gallery"> 

<ul id="pictures"> 
    <li class="img"> 
    <div class="desc">Hello World</div> 
    </li> 
    <li class="img"> 
    <div class="desc">Hello World</div> 
    </li> 
</ul> 
</div> 

很抱歉的混亂,但我有急事要完成這件事 - 所有的幫助是非常讚賞: D

+0

請看看上格式化後的準則,看看你能得到這個清理一點點。謝謝。 – 2010-12-01 14:52:13

+0

我已經格式化了它 - 你是指論壇發佈自己還是代碼? – 2010-12-01 14:57:56

回答