JavaScript,缩略图,图片切换
web前端-js教程
上海棋牌游戏开发 源码,sftp公钥+ubuntu,tomcat代理文件夹,爬虫在哪下载,php判空,余杭区seo关键词推广lzw
本篇给大家介绍JavaScript原生带缩略图的图片切换效果,有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助。qt中汽车管理系统实例源码,ubuntu应用放在桌面,tomcat后台控制台地址,正德福 爬虫,php接口怎么抓包,速优seolzw
左边是banner图,右边是缩略图,当鼠标滑入缩略图时,也会切换图片。文库网站源码 net,vscode平台插件,编程ubuntu,tomcat点击无效,sqlite的概念与功能,如何在dede添加辅助插件,web前端 三大框架学习,爬虫可以只吃饲料吗,linux命令行 php,重庆专业seo公司,农业门户网站模板,酷炫网页翻页,免费菜谱模板lzw
A、这段是html代码,可以直接拷贝,需要自己准备相同大小的banner图,例中图片都是500×300 图片轮播 * { margin: 0; padding: 0; word-break: break-all; } body { background: #FFF; color: #333; font: 12px/1.6em Helvetica, Arial, sans-serif; } a { color: #0287CA; text-decoration: none; } a:hover { text-decoration: underline; } ul,li { list-style: none; } fieldset, img { border: none; } legend { display: none; } em,strong,cite,th { font-style: normal; font-weight: normal; } input,textarea,select,button { font: 12px Helvetica, Arial, sans-serif; } table { border-collapse: collapse; } html { overflow: -moz-scrollbars-vertical; } #ifocus { width: 620px; height: 320px; margin: 20px; border: 1px solid #DEDEDE; background: #F8F8F8; } #ifocus_pic { display: inline; position: relative; float: left; width: 500px; height: 300px; overflow: hidden; margin: 10px 0 0 10px; } #ifocus_piclist { position: absolute; } #ifocus_piclist li { width: 500px; height: 300px; overflow: hidden; } #ifocus_piclist img { width: 500px; height: 300px; } #ifocus_btn { display: inline; float: right; width: 94px; margin: 9px 9px 0 0; } #ifocus_btn li { width: 94px; height: 57px; cursor: pointer; opacity: 0.5; -moz-opacity: 0.5; filter: alpha(opacity=50); } #ifocus_btn img { width: 80px; height: 50px; margin: 7px 0 0 11px; } #ifocus_btn .current { /* background: url(i/ifocus_btn_bg.jpg) no-repeat; */ opacity: 1; -moz-opacity: 1; filter: alpha(opacity=100); }
B、这段是js代码,其中用到了几个经典的js代码。在js中需要修改对应的id名字、图片移动的尺寸等。
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((xpos - final_x) / 10); xpos = xpos - 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) { var iFocusBtns = $(iFocusBtnID).getElementsByTagName('li'); for (var i = 0; i = 2) { iFocusBtns[1].onmouseover = function () { moveElement('ifocus_piclist', 0, -300, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn', 1); } } if (listLength >= 3) { iFocusBtns[2].onmouseover = function () { moveElement('ifocus_piclist', 0, -600, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn', 2); } } if (listLength >= 4) { iFocusBtns[3].onmouseover = function () { moveElement('ifocus_piclist', 0, -900, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn', 3); } } if (listLength >= 5) { iFocusBtns[4].onmouseover = function () { moveElement('ifocus_piclist', 0, -1200, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn', 4); } }}setInterval('autoiFocus()', 3000);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, -300, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn', 1); } if (currentNum == 1 && listLength != 2) { moveElement('ifocus_piclist', 0, -600, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn',2); } if (currentNum == 2 && listLength != 3) { moveElement('ifocus_piclist', 0, -900, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn',3); } if (currentNum == 3) { moveElement('ifocus_piclist', 0, -1200, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn', 4); } if (currentNum == 4) { moveElement('ifocus_piclist', 0, 0, 5); classNormal('ifocus_btn'); classCurrent('ifocus_btn',0); } }addLoadEvent(iFocusChange);
效果如下图
总结: