js仿土豆网带缩略图的焦点图片切换效果实现方法


Posted in Javascript onFebruary 23, 2015

本文实例讲述了js仿土豆网带缩略图的焦点图片切换效果实现方法。分享给大家供大家参考。具体实现方法如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>仿土豆网带缩略图的焦点图片切换效果</title>

<style type="text/css">

/* Reset style */

* { margin:0; padding:0; word-break:break-all; }

body { background:#FFF; color:#333; font:12px/1.6em Helvetica, Arial, sans-serif; }

h1, h2, h3, h4, h5, h6 { font-size:1em; }

a { color:#039; text-decoration:none; }

a:hover { text-decoration:underline; }

ul, li { list-style:none; }

fieldset, img { border:none; }

em, strong, cite, th { font-style:normal; font-weight:normal; }

/* Focus_change style */

#focus_change { position:relative; width:450px; height:295px; overflow:hidden; margin:20px 0 1px 60px; }

#focus_change_list { position:absolute; width:1800px; height:295px; }

#focus_change_list li { float:left; }

#focus_change_list li img { width:450px; height:295px; }

.focus_change_opacity { position:absolute; width:450px; height:70px; top:225px; left:0; background:#000; filter:alpha(opacity=50); -moz-opacity:0.5; opacity: 0.5; }

#focus_change_btn { position:absolute; width:450px; height:65px; top:225px; left:0; }

#focus_change_btn ul { padding-left:5px; }

#focus_change_btn li { display:inline; float:left; margin:0 15px; padding-top:12px; }

#focus_change_btn li img { width:76px; height:50px; border:2px solid #888; }

#focus_change_btn .current { background:url(/uploadfile/200901/1/6C164133877.gif) no-repeat 37px 8px;}

#focus_change_btn .current img { border-color:#EEE; }

</style>

<script type="text/javascript">

function $(id) { return document.getElementById(id); }

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(){

var focusBtnList = $('focus_change_btn').getElementsByTagName('li');

for(var i=0; i<focusBtnList.length; i++) {

focusBtnList[i].className='';

}

}

function focusChange() {

var focusBtnList = $('focus_change_btn').getElementsByTagName('li');

focusBtnList[0].onmouseover = function() {

moveElement('focus_change_list',0,0,5);

classNormal()

focusBtnList[0].className='current'

}

focusBtnList[1].onmouseover = function() {

moveElement('focus_change_list',-450,0,5);

classNormal()

focusBtnList[1].className='current'

}

focusBtnList[2].onmouseover = function() {

moveElement('focus_change_list',-900,0,5);

classNormal()

focusBtnList[2].className='current'

}

focusBtnList[3].onmouseover = function() {

moveElement('focus_change_list',-1350,0,5);

classNormal()

focusBtnList[3].className='current'

}

}

setInterval('autoFocusChange()', 5000);

var atuokey = false;

function autoFocusChange() {

$('focus_change').onmouseover = function(){atuokey = true}

$('focus_change').onmouseout = function(){atuokey = false}

if(atuokey) return;

var focusBtnList = $('focus_change_btn').getElementsByTagName('li');

for(var i=0; i<focusBtnList.length; i++) {

if (focusBtnList[i].className == 'current') {

var currentNum = i;

}

}

if (currentNum==0 ){

moveElement('focus_change_list',-450,0,5);

classNormal()

focusBtnList[1].className='current'

}

if (currentNum==1 ){

moveElement('focus_change_list',-900,0,5);

classNormal()

focusBtnList[2].className='current'

}

if (currentNum==2 ){

moveElement('focus_change_list',-1350,0,5);

classNormal()

focusBtnList[3].className='current'

}

if (currentNum==3 ){

moveElement('focus_change_list',0,0,5);

classNormal()

focusBtnList[0].className='current'

}

}

window.onload=function(){

focusChange();

}

</script>

</head>

<body>

<div id="focus_change">

<div id="focus_change_list" style="top:0; left:0;">

<ul>

<li><a href="https://3water.com/"><img src="/images/m03.jpg" alt="" /></a></li>

<li><a href="https://3water.com/"><img src="/images/m04.jpg" alt="" /></a></li>

<li><a href="https://3water.com/"><img src="/images/m09.jpg" alt="" /></a></li>

<li><a href="https://3water.com/"><img src="/images/m10.jpg" alt="" /></a></li>

</ul>

</div>

<div class="focus_change_opacity"></div>

<div id="focus_change_btn">

<ul>

<li class="current"><a href="#"><img src="/images/s3.jpg" alt="" /></a></li>

<li><a href="#"><img src="/images/s4.jpg" alt="" /></a></li>

<li><a href="#"><img src="/images/s9.jpg" alt="" /></a></li>

<li><a href="#"><img src="/images/s10.jpg" alt="" /></a></li>

</ul>

</div>

</div><!--focus_change end-->

<div style="height:20px; background:#EEE;"></div>

</body>

</html>

希望本文所述对大家的javascript程序设计有所帮助。

Javascript 相关文章推荐
一个不错的用JavaScript实现的UBB编码函数
Mar 09 Javascript
仿新浪微博登陆邮箱提示效果的js代码
Aug 02 Javascript
jQuery Form 表单提交插件之formSerialize,fieldSerialize,fieldValue,resetForm,clearForm,clearFields的应用
Jan 23 Javascript
JavaScript仿商城实现图片广告轮播实例代码
Feb 06 Javascript
详解Backbone.js框架中的模型Model与其集合collection
May 05 Javascript
javascript实现标签切换代码示例
May 22 Javascript
AngularJS 异步解决实现方法
Jun 12 Javascript
bootstrap switch开关组件使用方法详解
Aug 22 Javascript
微信小程序实现图片上传功能
May 28 Javascript
浅析Proxy可以优化vue的数据监听机制问题及实现思路
Nov 29 Javascript
3分钟了解vue数据劫持的原理实现
May 01 Javascript
javascript函数式编程基础
Sep 15 Javascript
JS实现仿中关村论坛评分后弹出提示效果的方法
Feb 23 #Javascript
jQuery+AJAX实现网页无刷新上传
Feb 22 #Javascript
AngularJS学习笔记之TodoMVC的分析
Feb 22 #Javascript
使用jquery组件qrcode生成二维码及应用指南
Feb 22 #Javascript
javascript实现博客园页面右下角返回顶部按钮
Feb 22 #Javascript
JS+CSS实现感应鼠标渐变显示DIV层的方法
Feb 20 #Javascript
js实现图片和链接文字同步切换特效的方法
Feb 20 #Javascript
You might like
这部番真是良心,画质好到像风景区,剧情让人跟着小公会热血沸腾
2020/03/10 日漫
BBS(php &amp; mysql)完整版(四)
2006/10/09 PHP
php获取mysql版本的几种方法小结
2008/03/25 PHP
PHP令牌 Token改进版
2008/07/18 PHP
PHP与MySQL开发的8个技巧小结
2010/12/17 PHP
php中创建和调用webservice接口示例
2014/07/25 PHP
php获取访问者IP地址汇总
2015/04/24 PHP
php实现求相对时间函数
2015/06/15 PHP
将PHP的session数据存储到数据库中的代码实例
2016/06/24 PHP
jQuery实现图片放大预览实现原理及代码
2013/09/12 Javascript
分享12个实用的jQuery代码片段
2016/03/09 Javascript
JavaScript实现打开链接页面的方式汇总
2016/06/02 Javascript
纯javascript版日历控件
2016/11/24 Javascript
AngularJS封装指令方法详解
2016/12/12 Javascript
vue绑定设置属性的多种方式(5)
2017/08/16 Javascript
node.js多个异步过程中判断执行是否完成的解决方案
2017/12/10 Javascript
浅析vue深复制
2018/01/29 Javascript
Vue.js 中取得后台原生HTML字符串 原样显示问题的解决方法
2018/06/10 Javascript
vue.js实现插入数值与表达式的方法分析
2018/07/06 Javascript
[02:28]DOTA2亚洲邀请赛附加赛 RECAP赛事回顾
2015/01/29 DOTA
使用Python编写vim插件的简单示例
2015/04/17 Python
使用Python绘制图表大全总结
2017/02/11 Python
Python3之文件读写操作的实例讲解
2018/01/23 Python
python实现内存监控系统
2021/03/07 Python
浅谈Python中(&amp;,|)和(and,or)之间的区别
2019/08/07 Python
2020最新pycharm汉化安装(python工程狮亲测有效)
2020/04/26 Python
python如何安装下载后的模块
2020/07/03 Python
python 制作磁力搜索工具
2021/03/04 Python
Hotels.com韩国:海外国内旅行所需的酒店和住宿预订网站
2020/05/08 全球购物
什么是View State?
2013/01/27 面试题
房产销售经理职责
2013/12/20 职场文书
房地产广告词大全
2014/03/19 职场文书
煤矿班组长竞聘书
2014/03/31 职场文书
党员对照检查材料
2014/09/22 职场文书
项目合作意向书
2015/05/08 职场文书
七年级作文(600字3篇)
2019/09/24 职场文书