用JS模拟向左移动的侧移式灯箱效果
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写的,你可以自己转换一下,很简单的。
#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);});
好了,这样大功告成了。我的效果图如下:一屏一屏地向左侧移动,看起来还是蛮动感的。
只是这个页面在博客园无法模拟啊,我再看看哪里问题。
花虎体坛点击热榜
![](http://www.playtigers.com/hbcms/upload/image/201009/small/74/7468_100929110211.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/yglzqbbkbe.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/23.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/ycbbjlhzr.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/21.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/small/62/6275_100809122523.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/22.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/15.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/11.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/big/74/7467_100806111447.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/zqbbzxyqpxz.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/big/54/5426_100805205255.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/zqbbylxebshxz.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/16.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/zqbbyszwx.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/ycnskyxz.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201101/small/44/4485_110125105543.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/small/74/7436_100809225502.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/24.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/jdsjcjjsbb.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/big/02/0242_100806113032.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/big/67/6755_100807132808.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/big/22/2215_100807144846.jpg)
![](http://www.playtigers.com/hbcms/upload/file/otherbaby100/0982_100722095025.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/small/28/2803_100819140107.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/small/80/8086_100819104808.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/yjdybbldlgs.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/adhszqbb.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/zqbbccjmhls.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/big/42/4255_100807123249.jpg)
![](http://www.playtigers.com/hbcms/upload/file/ss/25.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/small/16/1616_100824201035.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/small/07/0782_100828213737.jpg)
![](http://www.playtigers.com/hbcms/upload/file/otherbaby100/1.jpg)
![](http://www.playtigers.com/hbcms/upload/image/201008/small/11/1137_100818185336.jpg)
![](http://www.playtigers.com/hbcms/upload/file/football100/rbjlsctmrl.jpg)
下面把用到的JS脚本文件放在下面
http://files.cnblogs.com/obestboy/leftmove.js
转载于:https://www.cnblogs.com/obestboy/archive/2012/01/10/2318556.html
用JS模拟向左移动的侧移式灯箱效果相关推荐
- js模拟制作超逼真的雪花效果
<春雪> 唐·东方虬 春雪满空来,触处似花开. 不知园里树,若个是真梅. <红林擒近·寿词·满路花> 宋·陈允平 三万六千顷,玉壶天地寒.庾岭封的皪,淇园折琅.漠漠梨花烂漫,纷 ...
- html中实现添加水印的功能,JS模拟实现图片添加水印功能
JS模拟实现图片添加水印功能 ======================================================== 今天看到网友发帖求助如果在图片上自动添加水印的功能,于是 ...
- JS模拟实现图片添加水印功能
JS模拟实现图片添加水印功能 ======================================================== 今天看到网友发帖求助如果在图片上自动添加水印的功能,于是 ...
- Gremlins.js – 模拟用户随机操作的 JS 测试库
Gremlins.js 是基于 JavaScript 编写的 Monkey 测试库,支持 Node.js 平台和浏览器中使用.Gremlins.js 随机模拟用户操作:单击窗口中的任意位置,在表格中输 ...
- Node.js模拟发起http请求从异步转同步的5种方法
使用Node.js模拟发起http请求很常用的,但是由于Node模块(原生和第三方库)提供里面的方法都是异步,对于很多场景下应用很麻烦,不如同步来的方便.下面总结了几个常见的库API从异步转同步的几种 ...
- JS模拟模式窗口效果
<html> <head> <meta http-equiv="Content-Type" content="text/html; ...
- ul+js模拟select
ul+js模拟select html css .select_box{float: left; } .select_box input{width: 160px;height: 30px;text-a ...
- js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题...
js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题 js模拟form表单提交数据源码: /** * js模拟form表单提交 * @param ...
- [js] 模拟 localStorage 时如何实现过期时间功能
[js] 模拟 localStorage 时如何实现过期时间功能 1.存储时记录下有效截止时间 2.取数据时判断是否超过有效时间,在有效期内则返回,不在则提示或返回空并且将其删除 class MySt ...
最新文章
- 配置mysql主从服务器
- 关于Jvm知识看这一篇就够了
- GFStableList Adapter
- HDU5726 GCD(rmq+二分)
- linux进程卡住_鸿蒙系统,Linux? Android?
- ASP.NET Core 2.2 : 扒一扒新的Endpoint路由方案
- 命令查看linux主机配置
- 模态对话框与非模态对话的几种销毁方法与区别
- 特征金字塔 Feature Pyramid Networks for Object Detection
- mysql list转表_mysql系统表【转】
- 华为机试HJ75:公共子串计算
- java算术表达式求值-中缀表达式转后缀表达式
- UPnP 体系架构和基本原理 —— UPnP 网络组件
- 《亡灵序曲》各版本收集
- 如何使用FLASHGOT下载网页FLASH
- c语言 请编程序将 China 译成密码,分别用putchar和printf函数输出这5个字符
- 【Python】​​​​​​​turtle八边形绘制
- 裸机服务器装系统步骤,怎么给裸机装系统……
- 一个开发神器,可助程序员实现副业赚钱
- 相信机遇只能改变环境,努力是用来改变自己的。
热门文章
- gitlab集成openldap认证
- 清华大学刘知远:知识指导的自然语言处理
- 定时任务多线程-springboot
- 赌徒谬误论,投掷硬币,连续5次都是正面朝上,第6次正面反面的概率?
- 小技巧:如何让你办公更高效(技巧大集合持续更新中)!
- IPFS直播最详细解读—FileCoin Demo演示
- 我,94年山西人,矿山地质专业,自学软件当程序员,加班到窒息
- 计算机二级vp是什么意思,国家计算机二级VP笔试真题.doc
- mysql 授予所有权限_请问 :mysql数据库如何将某一个表的查询权限授予给所有用户?...
- Mac OS Catalina (10.15)下编译Redis Desktop Manager(RDM)