jsp+css实现图片自动轮换
jsp文件(片段)
<div id="ifocus">
<div id="ifocus_pic">
<div id="ifocus_piclist" style="left:0; top:0;">
<ul>
<li><a href="http://slide.news.sina.com.cn/s/slide_1_2841_17440.html" target="_blank"><img src='<%=path%>/images/picture/2011050903.jpg' alt="" /></a></li>
<li><a href="http://news.sina.com.cn/c/p/20101202/17289496.shtml" target="_blank"><img src='<%=path%>/images/picture/2011050901.jpg' alt="" /></a></li>
<li><a href="http://blog.sina.com.cn/u/1565088014" target="_blank"><img src='<%=path%>/images/picture/meinv/wangruoyi(2).jpg' alt="" /></a></li>
<li><a href="http://news.sina.com.cn/c/p/20101227/12109533.shtml" target="_blank"><img src='<%=path%>/images/picture/2011050902.jpg' alt="" /></a></li>
</ul>
</div>
<div id="ifocus_opdiv"></div>
<div id="ifocus_tx">
<ul>
<li class="current">云南空乘招募吸引众多俊男美女</li>
<li class="normal">女大学生学做痛经操</li>
<li class="normal">王若伊</li>
<li class="normal">陕西华县发现巨大地窖挖掘出数吨宋代古钱币</li>
</ul>
</div>
</div>
<div id="ifocus_btn">
<ul>
<li class="current"><img src='<%=path%>/images/picture/2011050903.jpg' alt="" /></li>
<li class="normal"><img src='<%=path%>/images/picture/2011050901.jpg' alt="" /></li>
<li class="normal"><img src='<%=path%>/images/picture/meinv/wangruoyi(2).jpg' alt="" /></li>
<li class="normal"><img src='<%=path%>/images/picture/2011050902.jpg' alt="" /></li>
</ul>
</div>
</div>
css文件
fieldset, img { border:none; }
#ifocus { width:477px; height:245px; margin:0px; border:1px solid #DEDEDE; background:#F8F8F8;}
#ifocus_pic { display:inline; position:relative; float:right; width:370px; height:225px; overflow:hidden; margin:10px 0 0 10px; }
#ifocus_piclist { position:absolute; }
#ifocus_piclist li { width:380px; height:225px; overflow:hidden; }
#ifocus_piclist img { width:380px; height:225px; }
#ifocus_btn { display:inline; float:right; width:91px; margin:4px 4px 0 0; }
#ifocus_btn li { width:91px; height:57px; cursor:pointer; opacity:0.5; -moz-opacity:0.5; filter:alpha(opacity=50); }
#ifocus_btn img { width:75px; height:48px; margin:7px 0 0 11px; }
#ifocus_btn .current { background: url(img/ifocus_btn_bg.gif) no-repeat; opacity:1; -moz-opacity:1; filter:alpha(opacity=100); }
#ifocus_opdiv { position:absolute; left:0; bottom:0; width:375px; height:35px; background:#000; opacity:0.5; -moz-opacity:0.5; filter:alpha(opacity=50); }
#ifocus_tx { position:absolute; left:8px; bottom:8px; color:#FFF; }
#ifocus_tx .normal { display:none; }
js文件
function $$(id) { return document.getElementById(id); }
function addLoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function(){
oldonload();
func();
}
}
}
function moveElement(elementID,final_x,final_y,interval) {
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos > final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}
function classNormal(iFocusBtnID,iFocusTxID){
var iFocusBtns= $$(iFocusBtnID).getElementsByTagName('li');
var iFocusTxs = $$(iFocusTxID).getElementsByTagName('li');
for(var i=0; i<iFocusBtns.length; i++) {
iFocusBtns[i].className='normal';
iFocusTxs[i].className='normal';
}
}
function classCurrent(iFocusBtnID,iFocusTxID,n){
var iFocusBtns= $$(iFocusBtnID).getElementsByTagName('li');
var iFocusTxs = $$(iFocusTxID).getElementsByTagName('li');
iFocusBtns[n].className='current';
iFocusTxs[n].className='current';
}
function iFocusChange() {
if(!$$('ifocus')) return false;
$$('ifocus').onmouseover = function(){atuokey = true};
$$('ifocus').onmouseout = function(){atuokey = false};
var iFocusBtns = $$('ifocus_btn').getElementsByTagName('li');
var listLength = iFocusBtns.length;
iFocusBtns[0].onmouseover = function() {
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
if (listLength>=2) {
iFocusBtns[1].onmouseover = function() {
moveElement('ifocus_piclist',0,-225,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',1);
}
}
if (listLength>=3) {
iFocusBtns[2].onmouseover = function() {
moveElement('ifocus_piclist',0,-450,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',2);
}
}
if (listLength>=4) {
iFocusBtns[3].onmouseover = function() {
moveElement('ifocus_piclist',0,-675,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',3);
}
}
}
setInterval('autoiFocus()',2500);
var atuokey = false;
function autoiFocus() {
if(!$$('ifocus')) return false;
if(atuokey) return false;
var focusBtnList = $$('ifocus_btn').getElementsByTagName('li');
var listLength = focusBtnList.length;
for(var i=0; i<listLength; i++) {
if (focusBtnList[i].className == 'current') var currentNum = i;
}
if (currentNum==0&&listLength!=1 ){
moveElement('ifocus_piclist',0,-225,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',1);
}
if (currentNum==1&&listLength!=2 ){
moveElement('ifocus_piclist',0,-450,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',2);
}
if (currentNum==2&&listLength!=3 ){
moveElement('ifocus_piclist',0,-675,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',3);
}
if (currentNum==3 ){
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
if (currentNum==1&&listLength==2 ){
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
if (currentNum==2&&listLength==3 ){
moveElement('ifocus_piclist',0,0,5);
classNormal('ifocus_btn','ifocus_tx');
classCurrent('ifocus_btn','ifocus_tx',0);
}
}
addLoadEvent(iFocusChange);
效果图
jsp+css实现图片自动轮换相关推荐
- html 图片自动大小,css图片自适应_用css让图片自动适应大小
摘要 腾兴网为您分享:用css让图片自动适应大小,政务易,悦读小说,优学堂,悟空识字等软件知识,以及小伴龙,水彩笔刷,昕薇,八门,暴雪战网app,我的世界启动器,中税网继续教育,湖南文交所,我的世界头 ...
- css实现图片自动渐变切换、element-plus 的修改el-table的(边框线为虚线、表头样式)
首先 放几张图片 <div id="slideshow"><img src="@/assets/banner-one.png" alt=&qu ...
- 纯css 图片自动旋转动画
css能否实现图片自动旋转动画呢?答案当然是肯定的, 首先看下效果: HTML代码 <img src="https://gimg2.baidu.com/image_search/src ...
- 微信小程序图片自动播放功能
小程序图片自动轮换滚动功能 在看小程序源码时,发现该小程序用内置组件"swiper"实现图片滚动功能.经过测试效果很不错,因此记录下实现方法. 使用小程序组件swiper实现滑块视 ...
- 怎样实现banner自动播放html,纯css实现轮播图banner自动轮换效果
话不多说 直接上代码 * { margin: 0; padding: 0; } .container { margin:300px auto; height: 400px; width: 1146px ...
- CSS: div高度自动适应背景图片的高度 How to get div height to auto-adjust to background size?...
原文:CSS: div高度自动适应背景图片的高度 How to get div height to auto-adjust to background size? 其实方法非常简单,直接写代码: &l ...
- html图片自动适应窗口大小,使用CSS自动调整浏览器大小的图片大小
当我调整浏览器窗口大小时,我想要所有(或只是一些)我的图片自动调整大小. 我发现了以下代码 – 它不做任何事情,虽然. HTML CSS body { font-family: Arial; font ...
- css实现背景图片自动适应
css实现背景图片自动适应 <!DOCTYPE html> <html lang="en"> <head><meta charset=&q ...
- html图片自动在div里放大,css图片自适应div大小怎么做
css图片自适应div大小怎么做 内容导读:css图片自适应div大小的控制,为了让图片能够更好的展示,建议使用max-width这个属性.不管是pc端还是移动端,或者是自适应网站,使用max-wid ...
- CSS样式图片放在DIV里面,自动填充充满,且不变形
CSS样式图片放在DIV里面,自动填充充满且不变形 一.图片用img标签存放 HTML如下: <div><img src="..." alt="&quo ...
最新文章
- python添加时间戳_Python 给某个文件名添加时间戳的方法
- 网易发布云计算战略,“为解放程序员而来”
- linux find命令使用示例
- qdebug重定向_每个Qter都该知道的qDebug
- Centos-Server-Nginx服务(编译安装)
- no instance(s) of type variable(s) X exist so that DataSource<X> conforms to DataStream<Order>
- [luoguP2324] [SCOI2005]骑士精神(A*?)
- ios解决button重复点击的问题
- VCL已死,RAD已死(插播)
- Linux部署Oracle
- ZXing开发彩色二维码
- python音乐播放器图片_Python音乐播放器
- error: ‘xcb_generic_event_t’ was not declared in this scope
- 禅说派-全图型PPT之图片处理技巧精粹
- 本周测试服务器角色转移系统仅开放转入,梦幻西游3月11日更新一览
- python爬虫论文参考文献格式_Python爬虫进阶必备 | XX文学加密分析实例
- 网页视频倍数播放代码
- 《江山美人》:程小东的利落与编剧群的故步自封
- [luogu#2019/03/10模拟赛][LnOI2019]长脖子鹿省选模拟赛赛后总结
- 2019-10-25考试