Magento产品模块细节图展示加入左右轮番功能

闲话少说,直接上代码
找到当前模板下的media.phtml
css部分

<style type="text/css">
ul, ol{list-style:none;margin:0px;padding:0px;}
li{list-style:none outside none;}
div.stylesgoleft{float:left;width:21px;height:28px;background:url('../media/arrowhead.png') no-repeat left top;margin:40px 10px 0 0px;cursor:pointer;}
div.stylesgoleft:hover{float:left;width:21px;height:28px;background:url('../media/arrowhead.png') no-repeat left -28px;margin:40px 10px 0 0px;cursor:pointer;}
div.playerdetail{width:172px;height:245px;background:#FFF;font-family:'微软雅黑';}
div.playerdetail div.detailimg{width:172px;height:124px;}
div.playerdetail div.detailimg img{width:172px;height:115px;}
div.playerdetail div.teanames{text-align:center;font-size:14px;margin-top:5px;color:#404040;}
div.playerdetail div.teadetail{width:156px;height:27px;margin:5px 8px;color:#666;}
div.playerdetail .checkdetail{width:134px;height:27px;display:block;background:url('../media/checkdetail.png') no-repeat;margin:18px;}
div.stylesgoright{float:left;width:21px;height:28px;background:url('../media/arrowhead.png') no-repeat left -56px;margin:40px 0 0 10px;cursor:pointer;}
div.stylesgoright:hover{float:left;width:21px;height:28px;background:url('../media/arrowhead.png') no-repeat left -84px;margin:40px 0 0 10px;cursor:pointer;}
div.maindiv1{float:left;width:495px;height:auto;overflow:hidden;position:relative;}
div.maindiv1 ul{position:absolute;left:0;top:0;}
div.maindiv1 ul li{float:left;width:172px;height:245px;margin-left:13px;}
#maindiv1 .more-views{width:2000px !important}
</style>

js部分

<script type="text/javascript">
window.onload = function () {
	var oBtnLeft = document.getElementById("goleft");
	var oBtnRight = document.getElementById("goright");
	var oDiv = document.getElementById("maindiv1");
	var oUl = oDiv.getElementsByTagName("ul")[0];
	var aLi = oUl.getElementsByTagName("li");
	var now = -1 * (aLi[0].offsetWidth + 1);
	oUl.style.width = aLi.length * (aLi[0].offsetWidth + 1) + 'px';
	oBtnRight.onclick = function () {
		var n = Math.floor((aLi.length * (aLi[0].offsetWidth + 1) + oUl.offsetLeft) / aLi[0].offsetWidth);
			move(oUl, 'left', oUl.offsetLeft + now);
	}
	oBtnLeft.onclick = function () {
		var now1 = -Math.floor((aLi.length / 1)) * 1 * (aLi[0].offsetWidth + 1);
			move(oUl, 'left', oUl.offsetLeft - now);
	}
	

};

function getStyle(obj, name) {
	if (obj.currentStyle) {
		return obj.currentStyle[name];
	}
	else {
		return getComputedStyle(obj, false)[name];
	}
}

function move(obj, attr, iTarget) {
	clearInterval(obj.timer)
	obj.timer = setInterval(function () {
		var cur = 0;
		if (attr == 'opacity') {
			cur = Math.round(parseFloat(getStyle(obj, attr)) * 100);
		}
		else {
			cur = parseInt(getStyle(obj, attr));
		}
		var speed = (iTarget - cur) / 6;
		speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
		if (iTarget == cur) {
			clearInterval(obj.timer);
		}
		else if (attr == 'opacity') {
			obj.style.filter = 'alpha(opacity:' + (cur + speed) + ')';
			obj.style.opacity = (cur + speed) / 100;
		}
		else {
			obj.style[attr] = cur + speed + 'px';
		}
	}, 30);
}  
</script>

html部分

<?php if (count($this->getGalleryImages()) > 1): ?>
	<div class="stylesgoleft" id="goleft"></div> //左边滑动按钮
	<div class="maindiv1 " id="maindiv1"> //整个more-views包含在这个div中间
    <ul class="more-views">
    <?php $i=1; foreach ($this->getGalleryImages() as $_image): ?>
        <li<?php if ($i==1): ?> class="selected"<?php endif; ?>>
            <a class="lightbox" role="button" href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize($resizeAsSquare[$i]); ?>" title="<?php echo $this->escapeHtml($_image->getLabel()) ?>" data-url-medium="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize($width,$maxHeight); ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(68); ?>" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>" width="68" height="68">
                <span class="a11y"><?php echo $this->__('Display Gallery Item %d', $i) ?></span>
            </a>
        </li>
    <?php $i++; endforeach; ?>
    </ul>
	</div>
	<div class="stylesgoright" id="goright"></div>//右边边滑动按钮
    <?php endif; ?>

不喜勿喷,尽情测试。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值