Archive

Archive for the ‘ecshop’ Category

转贴 ECSHOP通用首页最新商品滚动效果

October 23rd, 2011 小西的博客 No comments

原贴地址:hhttp://hi.baidu.com/javaplan/blog/item/e3ffa000abdfb38be950cd9b.html

 

滚动JS代码:

function Marquee()
{
this.ID = document.getElementById(arguments[0]);
this.Direction = arguments[1];
this.Step = arguments[2];
this.Width = arguments[3];
this.Height = arguments[4];
this.Timer = arguments[5];
this.WaitTime = arguments[6];
this.StopTime = arguments[7];
if(arguments[8])
this.ScrollStep = arguments[8]
else
this.ScrollStep = this.Direction>1 ? this.Width : this.Height;
this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
this.ID.style.overflowX = this.ID.style.overflowY = “hidden”;
this.ID.noWrap = true;
this.ID.style.width = this.Width;
this.ID.style.height = this.Height;
this.ClientScroll = this.Direction>1 ? this.ID.scrollWidth : this.ID.scrollHeight;
this.ID.innerHTML += this.ID.innerHTML;
this.Start(this,this.Timer,this.WaitTime,this.StopTime);
}
Marquee.prototype.Start = function(msobj,timer,waittime,stoptime)
{
msobj.StartID = function(){msobj.Scroll()}
msobj.Continue = function()
{
if(msobj.MouseOver == 1)
{
setTimeout(msobj.Continue,waittime);
}
else
{ clearInterval(msobj.TimerID);
msobj.CTL = msobj.Stop = 0;
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}
msobj.Pause = function()
{
msobj.Stop = 1;
clearInterval(msobj.TimerID);
setTimeout(msobj.Continue,waittime);
}
msobj.Begin = function()
{
msobj.TimerID = setInterval(msobj.StartID,timer);
msobj.ID.onmouseover = function()
{
msobj.MouseOver = 1;
clearInterval(msobj.TimerID);
}
msobj.ID.onmouseout = function()
{
msobj.MouseOver = 0;
if(msobj.Stop == 0)
{
clearInterval(msobj.TimerID);
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}
}
setTimeout(msobj.Begin,stoptime);
}
Marquee.prototype.Scroll = function()
{
switch(this.Direction)
{
case 0:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.WaitTime > 0)
{
this.ID.scrollTop += this.ScrollStep + this.Step – this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop >= this.ClientScroll)
{
this.ID.scrollTop -= this.ClientScroll;
}
this.ID.scrollTop += this.Step;
}
break;
case 1:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.WaitTime > 0)
{
this.ID.scrollTop -= this.ScrollStep + this.Step – this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop <= 0)
{
this.ID.scrollTop += this.ClientScroll;
}
this.ID.scrollTop -= this.Step;
}
break;
case 2:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.WaitTime > 0)
{
this.ID.scrollLeft += this.ScrollStep + this.Step – this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft >= this.ClientScroll)
{
this.ID.scrollLeft -= this.ClientScroll;
}
this.ID.scrollLeft += this.Step;
}
break;
case 3:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.WaitTime > 0)
{
this.ID.scrollLeft -= this.ScrollStep + this.Step – this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft <= 0)
{
this.ID.scrollLeft += this.ClientScroll;
}
this.ID.scrollLeft -= this.Step;
}
break;
}
}

 

 

——————————————————-

注意:此效果任何模 板可以通用!!
一、将顶部滚动JS代 码保存为gundong.js文 件拷贝到根目 录JS文件夹里

二、在首页模板文件index.dwt的<head></head>标签之间添加代 码:
<script src=”js/gundong.js” language=”JavaScript” type=”text/javascript”></script>

三、找到要修改的展示产品的库文件,比如要修改产 品上架的滚动效果

在library文件夹里找到recommend_new.lbi文件在最上面添加代码:
<SCRIPT defer>
new Marquee(“textdiv”,0,4,760,229,1,3000,1)
</SCRIPT>

然 后在<div id=”show_new_area”>之前添加代码:
<div id=textdiv>
结尾记得要添加</div>

这样就OK了~

—————————————————————–
代 码实例:recommend_new.lbi的修改代码如下:

<SCRIPT defer>
new Marquee(“textdiv”,0,4,760,229,1,3000,1)
</SCRIPT>

<meta http-equiv=”Content-Type” content=”text/html; charset=gbk”>
<!– {if $new_goods} –>
<!– {if $cat_rec_sign neq 1} –>
<div >
<h3>
<div id=”itemNew”>
{if $cat_rec[2]}
<h2><a href=”javascript:void(0)”>{$lang.all_goods}</a></h2>
{foreach from=$cat_rec[2] item=rec_data}
<h2 ><a href=”javascript:void(0)”>{$rec_data.cat_name}</a></h2>
{/foreach}
{/if}
</div>
<a href=”../search.php?intro=new”><img src=”images/bnt_more_1.gif” /></a>
<span></span>
</h3>
</div>
<DIV >
<!– {/if} –>
<!–{foreach from=$new_goods item=goods}–>
<div>

<a href=”{$goods.url}”><img src=”{$goods.thumb}” alt=”{$goods.name|escape:html}” border=”0″ onmouseover=”showtrail(‘{$goods.goods_img}’)” onmouseout=”hidetrail()” /></a><br />

<p><a href=”{$goods.url}” title=”{$goods.name|escape:html}”>{$goods.short_style_name}</a></p>
<font >
<!– {if $goods.promote_price neq “”} –>
{$lang.promote_price}<b>{$goods.promote_price}</b><br />
<!– {else}–>
{$lang.shop_price}<b>{$goods.shop_price}</b><br />
<!–{/if}–>
</font>
<a href=”javascript:collect({$goods.id})”><img src=”images/but_coll.jpg”></a> <a href=”javascript:addToCart({$goods.id})”><img src=”images/but_buy.jpg”></a>
</div>
<!–{/foreach}–>
<!– {if $cat_rec_sign neq 1} –>
</div>
</DIV>

Categories: ecshop Tags: