demo01.html

Home  >  Article  >  Web Front-end  >  jquery focus image switching (digital annotation/manual/auto play/horizontal scrolling)_jquery

jquery focus image switching (digital annotation/manual/auto play/horizontal scrolling)_jquery

WBOY
WBOYOriginal
2016-05-16 17:42:561391browse
jquery focus image switching (digital annotation/manual/auto play/horizontal scrolling)_jquery
demo01.html
复制代码 代码如下:





手动滚动图片









  • jquery focus image switching (digital annotation/manual/auto play/horizontal scrolling)_jquery

  • images/2.jpg

  • images/3.jpg

  • images/4.jpg

  • images/5.jpg

  • images/6.jpg







imgfocus-0.1.0.js
复制代码 代码如下:

/**
* 手动滚动图片
*
**/
$.extend({
imgfocus: function(opt, callback) {
//alert("suc");
this.defaults = {
// 滚动区域id
objId: "",
// 是否在大图下方显示标题
showTitle: false,
// 每行的宽度
width: 300,
// div的高度
height: 100,
// 每次滚动的行数
line: 1,
// 自动滚动的行数
autoLine: 1,
// 动作时间
speed: 0,
// 滚动间隔
interval: 3000,
// 图片根目录
imgPath: "",
// 间隔句柄,不需要设置,只是作为标识使用
picTimer: 0,
// 按钮透明度
opacity: 0.3
};
//参数初始化
var opts = $.extend(this.defaults, opt);
// 定义外层元素样式
$("#" + opts.objId).css({
"position": "relative",
"overflow": "hidden",
"width": (opts.line * opts.width) + "px"
});
// 定义ul样式
$("#" + opts.objId + " ul").css({
"width": opts.width * $("#" + opts.objId + " ul").find("li").size() + "px",
"height": opts.height + "px"
});
// 定义li样式
$("#" + opts.objId + " ul li").css({
"display": "block",
"float": "left",
"width": opts.width + "px",
"height": opts.height + "px"
});
// 定义img样式
$("#" + opts.objId + " ul li img:first").css({
"display": "block",
"float": "left",
"width": opts.width + "px",
"height": opts.height + "px"
});
if (opts.showTitle) {
$("#" + opts.objId).append("
");
$("#imgfocus_banner").css({
"width": opts.width + "px",
"height": "20px",
"background": "#333",
"position": "absolute",
opacity: 0.7,
"text-align": "center",
"color": "#FFF",
"left": "0px",
"top": (opts.height - 20) + "px"
});
$("#imgfocus_banner").html("
");
$("#imgfocus_banner_title").text("text");
$("#imgfocus_banner_title").css({
"display": "block",
"float": "left",
"width": (opts.width - 20 * $("#" + opts.objId + " ul li").size()) + "px",
"height": "20px"
});
$("#" + opts.objId + " ul li").each(function(index) {
$(this).attr("index", index);
$("#imgfocus_banner").append("
" + (index + 1) + "
");
var bgColor;
$("#imgfocus_banner_squ" index).mouseover(function() {
bgColor = $(this).css("배경");
$( this).css({
"배경": "#CC0"
})
}).mouseleave(function() {
$(this).css({
" background": bgColor
});
});
// 数字块点击事件
$("#imgfocus_banner_squ" index).click(function() {

var length = $("#" opts.objId " ul li[index=" index "]").prevAll().size()
var scrollWidth = 0 - length * opts.width - (0 - $( "#" opts.objId).find("ul:first").css("margin-left").replace("px", ""))
$("#" opts.objId). find("ul:first").animate({
marginLeft: scrollWidth
},
6,
function() {
for (i = 1; i $("#" opts.objId).find("li:first").appendTo($("#" opts.objId).find("ul:first"))
}
$("#" opts.objId).find("ul:first").css({
marginLeft: 0
})
var index = $("#" opts .objId).find("li:first").attr("index");
// 数字标签전체 부분变灰color
$(".imgfocus_banner_squ").css({
"배경" : "#CCC"
})
// 活动的数字标签变红color
$("#imgfocus_banner_squ" index).css({
"배경": "#C00"
});
bgColor = "배경:#C00";
변경제목();
});
});
});
// 数字块样式
$(".imgfocus_banner_squ").css({
"display": "block",
"float": "left",
"margin" : "1px",
"너비": "18px",
"높이": "18px",
"색상": "#000",
"배경": "#CCC"
});
// 第一个数字块样式
$(".imgfocus_banner_squ:first").css({
"배경": "#C00"
});
}
/**
* 자동 가로 스크롤
*/
function scrollLeft() {
var scrollWidth = 0 - opts.autoLine * opts.width - (0 - $("#" opts.objId ).find("ul:first").css("margin-left").replace("px", ""));
$("#" opts.objId).find("ul:first").animate({
marginLeft: scrollWidth
},
opts.speed,
function() {
for (i = 1; i $("#" opts.objId).find("li:first").appendTo($("#" opts .objId).find("ul:first"));
}
$("#" opts.objId).find("ul:first").css({
marginLeft: 0
});
var index = $("#" opts.objId).find("li:first").attr("index");
changeTitle()// 数字标签전체부变灰color
$(".imgfocus_banner_squ").css({
"배경": "#CCC"
})
// 活动的数字标签变红color
$ ("#imgfocus_banner_squ" index).css({
"배경": "#C00"
})
});
};
/**
* 제목 변경
*/
함수changeTitle(){
$("#imgfocus_banner_title").text($("#" opts.objId).find("li:first img: 첫 번째").attr("alt"));
}
/**
* 마우스를 위로 슬라이드한 후 버튼 표시
*/
$("#" opts.objId).hover(function() {
$("#button_left").css({
불투명도: 1
});
$("#button_right").css({
불투명도: 1
})
},
function() {
$("#button_left").css({
불투명도: opts.opacity
})
$("#button_right").css({
불투명도: opts.opacity
});
}).trigger("mouseleave");
/**
* 첫 번째로 실행되는 기능
* 초점 영상 위로 마우스를 슬라이드하면 자동 재생을 중지하고, 마우스를 슬라이드하면 자동 재생을 시작합니다
*/
// 初始化标题
changeTitle();
$("#" opts.objId).hover(function() {
clearInterval(opts.picTimer);
},
function() {
opts.picTimer = setInterval( function() {
scrollLeft();
},
opts.interval); // 自动播放的间隔,单位:毫秒
}).trigger("mouseleave");
}
});

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn