您的位置:首页 > Web前端 > JavaScript

用JS模拟向左移动的侧移式灯箱效果

2012-01-10 21:56 267 查看
HTML结构如下:

其中ahot是表示有几屏,现在正移动到哪一屏;

ohot表示整个灯箱,ihot也是整个灯箱,但先是隐藏起来的;

而dhot表示一屏灯箱,此处共四屏;

hot_div是表示一屏灯箱的一行,共四行,在实际案例里一行有三幅图片。

<div class="gg_title" id="leftmove_title"><p>花虎体坛点击热榜</p></div>
<div class="gg_body" id="leftmove">
<div id="ahot"><div><a>1</a><a>2</a><a>3</a><a>4</a></div></div>
<div id="ohot">
<div id="ihot" class="hidden">

<div class="dhot">
<div class="hot_div">

</div>

<div class="hot_div">

</div>

<div class="hot_div">

</div>

</div>

<div class="dhot">
<div class="hot_div">

</div>

<div class="hot_div">

</div>

<div class="hot_div">

</div>

</div>

<div class="dhot">
<div class="hot_div">

</div>

<div class="hot_div">

</div>

<div class="hot_div">

</div>

</div>

<div class="dhot">
<div class="hot_div">

</div>

<div class="hot_div">

</div>

<div class="hot_div">

</div>

</div>

</div>
</div>
</div>
<div class=vertical_space></div>


我这里直接贴上我实际的代码,供参考

接下来就那些div的class的定义了,我直接贴代码,我是用JS写的,你可以自己转换一下,很简单的。

#leftmove {width:386px;height:480px; position:relative;right:0px;}
#ahot {width:386px;height:25px;background-color:#0099CC;}
#ohot {width:386px;height:480px; overflow:hidden; position:relative;top:10px;}
#ihot {width:1800px;height:480px;position:relative;}
.dhot {float:left;width:386px;height:480px;}
#ahot a {float:left;position:relative;left:15px;display:block;cursor:pointer;width:30px;height:25px;line-height:25px;text-align:center;background: #0099CC;color:white;font-size:20px;font-weight:bold;}
#ahot div {float:left;display:block;position:relative;left:100px;}
#right_ad160x600 {float:right;width: 165px; height: 600px;background-color:#FF0000;color:#fff;font-size:20px;font-weight:bold;position:relative;text-align:center;top:40px;right:8px;}
.hot_div {position:relative;left:15px;width:386px;height:150px;}
.top_small_div {float:left;width:120px;height:120px;margin:auto auto auto 2px ;}
.top_small_img {width:100px;height:100px;border:2px solid #EAfAFA;padding:2px;}
.top_small_text {display:block;width:100px; height:20px;line-height:20px;overflow:hidden;text-align:center;}
.right_small_div {text-align:center;width:120px;height:120px;margin:auto auto auto 5px ;}
.my_colee_bottom {width: 155px; height: 700px; overflow: hidden;position:relative;top:5px;}
.gg_title {width:388px;background-color: #70B7C0;height:25px;background-repeat:no-repeat;font-weight: bold;padding-top: 5px;color:#fff;font-size:14px;position:relative;right:0px;}
.gg_body {width:386px;background-color:#DDDDDD;position:relative;right:0px;border-left: 1px solid #9599AD; border-right:1px solid #9599AD; border-bottom:2px solid #9599AD;}
.gg_title p {text-align:center;margin:0px;}
.vertical_space {height:5px;}
.hidden { display:none;}
#ad300x250 {width:305px;height:255px;font-size:20px;font-weight:bold;position:relative;text-align:center;left:10px;color:white;}
#ad300x2501 {width:305px;height:255px;font-size:20px;font-weight:bold;position:relative;text-align:center;left:10px;}
下面就是JS脚本了,仔细看吧,用了jquery,你还得在你的HTML文件里加上jquery

<script src="http://www.playtigers.com/hbcms/script/jquery/jquery_1.3.1.js" type="text/javascript"></script>


var hottotal=$(".dhot").length;
var hotwidth=$("#ohot").width();
var hotdistance=20;
var hotleft1=0;
var hotleft2=0;
var hotdis=0;
var hot2t,hot3t,hot4t;
function hotmove(){
var hotnext=hotdis+1;
if(hotnext>hottotal-1) {
hotleft1=-1*hotnext*hotwidth;
hotleft2=hotleft2+hotdistance;
hotleft3=hotleft2+"px";
if(hotleft2<0) {
if(hot2t) clearTimeout(hot2t);
if (hot4t) clearTimeout(hot4t);
$("#ihot").css({"left":hotleft3});
hot3t=setTimeout("hotmove()",10);
}
else {
if(hot3t) clearTimeout(hot3t);
$("#ahot a").eq(3).css({"color":"#fff"});
$("#ahot a").eq(0).css({"color":"red"});
$("#ihot").css({"left":"0px"});
hotdis=0;
hot4t=setInterval("hotmove()",8000);
}
}
else {
hotleft1=-1*hotnext*hotwidth;
hotleft2=hotleft2-hotdistance;
if(hotleft1<hotleft2) {
if (hot4t) clearTimeout(hot4t);
hotleft3=hotleft2+"px";
$("#ihot").css({"left":hotleft3});
hot2t=setTimeout("hotmove()",20);
}
else {
$("#ahot a").eq(hotdis).css({"color":"#fff"});
$("#ahot a").eq(hotnext).css({"color":"red"});
$("#ihot").css({"left":hotleft1});
if(hot2t) clearTimeout(hot2t);
hotdis=hotnext;
hot4t=setInterval("hotmove()",8000);
}
}
}

$(document).ready(function(){
$("#ahot a").eq(0).css({"color":"red"});
$(function(){
$('#leftmove').hover(
function () { if (hot4t) clearTimeout(hot4t);},
function () {hot4t=setInterval("hotmove()",8000);}
);

$('#ahot a').click(function(){
var thishot=$("#ahot a").index($(this));
$("#ahot a").eq(hotdis).css({"color":"#fff"});
$("#ahot a").eq(thishot).css({"color":"red"});
var thisleft=-1*thishot*hotwidth;
$("#ihot").css({"left":thisleft});
hotdis=thishot;
}
);
});
hot4t=setInterval("hotmove()",8000);
});


好了,这样大功告成了。我的效果图如下:一屏一屏地向左侧移动,看起来还是蛮动感的。

只是这个页面在博客园无法模拟啊,我再看看哪里问题。

花虎体坛点击热榜

1234




“第一足球宝贝”刘羽琦拍泳装大片展魔鬼身材




宝贝叫嚣乳神




赛车宝贝媚卧宝马拍丰韵写|真




英超波霸姬丽-哈泽尔最新写|真




《男人帮》评选10年来体坛10大性|感尤物




新一代英超波霸写|真 黑丝内衣难掩大波诱|惑




泰国赛车宝贝妖娆写|真别具风情




足球宝贝江伊涵白色系诱|惑写|真




足球宝贝突发奇想 英国旗与腾叶上写|真秀身材




俄罗斯网坛神仙姐姐德门蒂耶娃拍鬼魅写|真




足球宝贝张馨予情景俏皮写|真




玉女掌门人马露儿 妩媚性|感马术写|真




足球宝贝耶律雪儿变身田园花仙子




冰上精灵,花样之花金妍儿图集




足球宝贝浴室照外泄 尺度之大令人惊讶




英超女神最新狂野写|真 骄人身材一览无余




巴拉圭乳神拉萨里-里克尔梅露|点照全集




盘点女明星运动写|真,看看谁最动感十足?




美国足球悍将迎娶花花公子女郎




绝对视觉冲击:绝色宝贝床上联手大秀丰胸美|腿




挪威现男版空翻掷界外球 看呆裁判




最靓足球宝贝”周伟童最新写|真展现丝滑般白皙肌肤




足球宝贝现F4 刮起一股白色清新旋风




著名女演员董璇变身网球宝贝 唯美写|真如梦如幻




潘晓婷亮相《男人装》 成最保守“装女郎”




英超足球宝贝以手当胸拍大尺度视频写|真




意甲第一宝贝贝伦-罗德里格斯写|真




爱戴化身足球宝贝拍靓丽写|真




足球宝贝晨晨姐妹花蕾丝大秀姐妹情深




盘点:曾登上《男人帮》封面的体坛十大美女




自行车女皇写|真展露曼妙曲线




落选的美图也精彩:“金镜头奖”体育美图欣赏




C罗女友伊丽娜为GQ拍性|感写|真




美女宝贝诠释柔情现代五项




眼镜宝贝黑丝秘书装在诱|惑谁?




日本J联赛长腿美乳娘 钢巴队足球宝贝水木秋

下面把用到的JS脚本文件放在下面

http://files.cnblogs.com/obestboy/leftmove.js
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: