数字化技能提升教程,数字化时代生存宝典

数字化百科 / 产品文档 / Gallery:外观主题:AutoRC JavaScript

Gallery:外观主题:AutoRC JavaScript

查看全部产品文档命名空间:Gallery

这是AutoRC外观主题的JavaScript源代码。

/**
* 将边栏或相册容器的高度设为较高的那个值
*/
function setWidthHeights() {
var sidebar = document.getElementById('sidebar');
var album = document.getElementById('album');
// 相片页面
var photo = document.getElementById('photo');
if (photo) {
var photoWidth = album.offsetWidth - sidebar.offsetWidth;
photo.style.width = (photoWidth - 18) + 'px';
// 相册页面
} else {
var item = getElementsByClassName('item', 'div');
var albumWidth = album.offsetWidth - sidebar.offsetWidth;
var columns = Math.floor(albumWidth / item[0].offsetWidth);
var difference = albumWidth - (columns * item[0].offsetWidth);
var newItemWidth = (difference / columns) + item[0].offsetWidth - 18;
for (var i=0; i item[i].style.width = newItemWidth + 'px';
}
}
// 将边栏高度和相册/相片容器高度设为均等
if (sidebar.offsetHeight > album.offsetHeight) {
album.style.height = sidebar.offsetHeight + 'px';
} else {
sidebar.style.height = album.offsetHeight + 'px';
}
}
function getElementsByClassName(cssclass, element) {
var arr = new Array();
var elem;
var elems = document.getElementsByTagName(element);
for (var cls, i = 0; (elem = elems[i]); i++ ) {
if (elem.className == cssclass) {
arr[arr.length] = elem;
}
}
return arr;
}