日期:2014-05-16 浏览次数:20387 次
var slide = function(div_id,scro_direction,speed,width,height){ return new slide.prototype.init(div_id,scro_direction,speed,width,height); } slide.prototype = { init:function(div_id,scro_direction,speed,width,height){ }, ..... } slide.prototype.init.prototype = slide.prototype;
------解决方案--------------------
问题不大
1、示例的 html 中两个 id 重名,而实际控制时 id 必须唯一
2、需用数组保存实例的id,以便于定时控制
------解决方案--------------------
实际上仔细观察你会发现
window.onload = function () { slide.init('con', 'top', 30, '200px', '200px'); slide.init('coe','top',30,'200px','200px'); }
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>img_slide</title> <script type="text/javascript" src="javascripts/slide.js"></script> <script type="text/javascript"> /** * @author jiashu */ var slide = { div_id:null, obj:null, obj_child1:null, obj_child2:null, time_id:null, //div_id 住容器的ID scro_direction 图片滚动方向 speed 滚动速度 init:function (div_id, scro_direction, speed, width, height) { if (document.getElementById(div_id) == null) { return false; } var container = document.getElementById(div_id);// slide.div_id = div_id; var inner_html = container.innerHTML; container.innerHTML = ""; var container_c1 = this.create_container("div", div_id + "1", inner_html); this.obj_child1 = div_id + "1";//对第一个字容器进行处理 var container_c2 = this.create_container("div", div_id + "2", inner_html); this.obj_child2 = div_id + "2";//对第二个子容器处理 container.appendChild(container_c1); container.appendChild(container_c2); container.style.overflow = "hidden"; container.style.width = width; container.style.height = height; container.scro_direction = scro_direction; container.speed = speed; this.start.call(container); container.onmouseout = slide.start; container.onmouseover = slide.stop; }, stop:function () { clearInterval(slide.time_id); }, start:function () { var con = slide.obj = this; slide.time_id = setIn