jQuery A plug-in for image switching_jquery
以下是参数说明:
参数名称 | 描述 |
delay | 图片切换速度,单位毫秒 |
maskOpacity | 遮罩层透明度,1为不透明,0为全透明 |
numOpacity | 数字按钮透明度,1为不透明,0为全透明 |
maskBgColor | 遮罩层背景色 |
textColor | 标题字体颜色 |
numColor | 数字按钮字体颜色 |
numBgColor | 数字按钮背景色 |
alterColor | 数字按钮选中项字体颜色 |
alterBgColor | 数字按钮选中项背景颜色 |
- 插件名称:ImageScroll
(function($){
$.fn.ImageScroll = function(options) {
var defaults = {
delay: 2000,
maskOpacity: 0.6,
numOpacity: 0.6,
maskBgColor: "#000",
textColor: "#fff",
numColor: "#fff",
numBgColor: "#000",
alterColor: "#fff",
alterBgColor: "#999"
};
options = $.extend(defaults, options);
var _this = $(this).css("display", "none");
var _links = [], _texts = [], _urls = [];
var _list = _this.find("a");
var _timer;
var _index = 0;
_list.each(function(index){
var temp = $(this).find("img:eq(0)");
_links.push($(this).attr("href"));
_texts.push(temp.attr("alt"));
_urls.push(temp.attr("src"));
});
if(_list.length <= 0) {
return;
}
else {
_this.html("");
}
var _width = _this.width();
var _height = _this.height();
var _numCount = _list.length;
var _numColumn = Math.ceil(_numCount / 2);
var _img = $("").css({"display":"block", "position":"absolute","top":"0px","left":"0px", "z-index":"2", "width":_width "px", "height":_height "px", "background":"url(" _urls[0] ")"}).appendTo(_this);
var _mask = $("").attr("style","opacity:" options.maskOpacity)
.css({"position":"absolute", "left":"0px", "bottom":"0px", "z-index":"3", "width":_width "px", "height":"46px", "opacity":options.maskOpacity, "background-color":options.maskBgColor}).appendTo(_this);
var _num = $("").attr("style","opacity:" options.numOpacity)
.css({"position":"absolute", "right":"0px", "bottom":"0px", "z-index":"5", "width":_numColumn*22, "opacity":options.numOpacity, "height":"44px"}).appendTo(_this);
var _text = $("").css({"position":"absolute", "left":"0px", "bottom":"0px", "z-index":"4", "padding-left":"10px", "height":"44px", "line-height":"44px", "color":options.textColor}).html(_texts[0]).appendTo(_this);
for(var i = 0; i < _numCount; i )
{
$("").html(i 1)
.css({"float":"left", "width":"20px", "height":"20px", "text-align":"center", "background-color":options.numBgColor, "margin":"0px 2px 2px 0px", "cursor":"pointer", "line-height":"20px", "color":options.numColor})
.mouseover(function() {
if(_timer) {
clearInterval(_timer);
}
}).mouseout(function() {
_timer = setInterval(alter, options.delay);
}).click(function(){
numClick($(this));
}).appendTo(_num);
}
var _tempList = _num.find("a");
function alter() {
if(_index > _numCount-1) {
_index = 0;
}
_tempList.eq(_index).click();
}
function numClick(obj) {
var i = _tempList.index(obj);
_tempList.css({"background-color":options.numBgColor, "color":options.numColor});
obj.css({"background-color":options.alterBgColor, "color":options.alterColor});
_img.attr({"href":_links[i], "target":"_blank"})
.css({"opacity":"0", "background":"url(" _urls[i] ")"})
.animate({"opacity":"1"}, 500);
_text.html(_texts[i]);
_index = i 1;
}
setTimeout(alter, 10);
_timer = setInterval(alter, options.delay);
_this.css("display", "block");
};
})(jQuery);
- 调用代码
- Running results
- Call with parameters
<script> <br>$("#scroll").ImageScroll({delay:500, maskBgColor:"#ff0000"}); <br></script>
- Running results

Summary
It’s just a small plug-in, and the customizability may not be very good. You can take a look and modify it. It seems that IE8 still has a small bug, which will be corrected in a while. Upload again. If you find any bugs, please reply and tell me so that I can make corrections in time. If you have any suggestions for optimizing the code, please tell me to help me as a newbie learn, =.=

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to achieve seamless left and right sliding switching effect of images with JavaScript? With the development of the Internet, images are often used as important elements of the page in web design. The switching effect of pictures plays an important impact on the beauty and interactivity of the page. In this article, we will explore how to use JavaScript to achieve a seamless left-right sliding switching effect of images, and attach specific code examples. To achieve the seamless left and right sliding switching effect of pictures, you first need to do the following: Create a picture container and use

Methods and techniques on how to achieve image carousel effects through pure CSS. In modern web design, image carousel effects are often used to display multiple images or advertisements in turn. There are many ways to achieve an image carousel effect, one of the common ways is to use CSS animation. This article will introduce methods and techniques on how to achieve image carousel effects through pure CSS, and provide specific code examples. 1. HTML structure First, the image elements for carousel need to be prepared in HTML. Here is a simple HTML structure example: &l

Creating responsive image switching effects is one of the common tasks in front-end development. In this article, we will use HTML, CSS and jQuery to achieve this effect. Below are detailed steps and specific code examples. HTML structure First, we need to create the HTML structure required for the image switching effect. You can use the following code example to create a simple HTML structure. <divclass="slider-container">

How to achieve image switching and carousel effects through Vue? Vue is a JavaScript framework for building user interfaces that provides an elegant and efficient way to handle data and interaction logic in web applications. One of the many great features of Vue is that it can easily handle image switching and carousel effects. In this article, we will introduce how to use Vue to achieve these effects. First, we need to prepare some basic HTML structures and styles to display images. We can use <i

How to use JavaScript to achieve the gradient effect of image switching? With the development of the Internet, website design pays more and more attention to user experience. Image switching is one of the common interactive effects on websites. Gradient switching of images can better attract users' attention. This article will introduce how to use JavaScript to achieve the gradient effect of image switching, and provide specific code examples. Before we start, we need to prepare some image resources. Suppose we have three pictures, namely "image1.jpg", "

How can JavaScript achieve a seamless left and right sliding switching effect of an image while adding zoom and fade animations? In website development, the sliding switching effect of images is a very common requirement. Here we will introduce how to use JavaScript to achieve a left and right seamless sliding switching effect, while adding zoom and fade animations. This article will provide detailed code examples so that you can easily achieve this effect. First, we need to prepare a container in HTML to place images, and set the container's

How to use Layui to achieve the image switching carousel effect requires specific code sample title: Detailed explanation of using Layui to achieve the image switching carousel effect Introduction: In modern web design, the image switching carousel effect has become one of the common elements. Using image carousels can make web pages more dynamic and attractive. This article will use Layui as the basis to introduce how to achieve the image switching carousel effect, and give specific code examples. 1. Introduction to Layui carousel component Layui is a classic front-end UI framework, which includes

How to use Layui to achieve image switching and stretching effects. In recent years, with the rapid development of Web front-end technology, more and more frameworks and libraries are used to beautify and enhance the functions of web pages. Among them, Layui is a very popular front-end framework that provides rich UI components and easy-to-use function extensions. This article will introduce how to use Layui to achieve image switching and stretching effects, and give specific code examples. 1. Implementation of image switching effect HTML structure First, we need to prepare some HTML structures for
