1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| window.onload = function () { var imgBottom = document.getElementsByClassName('img-bottom') var imgToggle = document.getElementsByClassName('img')
var attrArr = [ 'leftImg', 'topImg', 'scaleImg', 'scaleImgs', 'scaleRotateImg' ]
var getCls = function (element) { return element.getAttribute('class') } var setCls = function (element, cls) { return element.setAttribute('class', cls) } var addCls = function (element, cls) { var baseCls = getCls(element) if (baseCls.indexOf(cls) == -1) { setCls(element, baseCls + ' ' + cls) } }
var delCls = function(element, cls) { var baseCls = getCls(element) if(baseCls.indexOf(cls) != -1){ setCls(element, baseCls.split(cls).join(' ').replace(/\s+/g, ' ')) } }
var toggleImg = function (i) { return function () { ImgAddIndex(i) } } for (var i = 0; i < imgBottom.length; i++) { imgBottom[i].onclick = toggleImg(i) }
function ImgAddIndex (i) { for(var j = 0;j<imgToggle.length;j++) { imgToggle[j].style.zIndex = 0 delCls(imgToggle[j], 'active') }
addCls(imgToggle[i], 'active') imgToggle[i].style.zIndex = 9; } }
|